【PB续命05】WinHttp.WinHttpRequest的介绍与使用

0 WinHttp.WinHttpRequest简介

winhttp.winhttprequest是Windows操作系统中的一个API函数,用于创建和发送HTTP请求。它可以用于从Web服务器获取数据,或将数据发送到Web服务器。该函数提供了许多选项,例如设置请求头、设置代理服务器、设置超时时间等。它是一个非常强大的工具,可以帮助开发人员轻松地与Web服务器进行通信。
winhttp.winhttprequest.5.1
wihttp.winhttprequest.5.1是一个Microsoft Windows操作系统中的COM组件,用于在应用程序中进行HTTP请求和响应。它提供了一种简单的方法来与Web服务器进行通信,可以用于发送和接收HTTP请求和响应,支持各种HTTP方法,如GET、POST、PUT、DELETE等。它还提供了一些其他功能,如设置请求头、设置代理服务器、设置超时等。

1 创建PB窗口

为了演示winhttp.winhttprequest的使用创建一PB测试窗口w_restful如下:
在这里插入图片描述
窗口w_restful代码如下:

forward
global type w_restful from window
end type
type mle_resp from multilineedit within w_restful
end type
type st_3 from statictext within w_restful
end type
type cb_delete from commandbutton within w_restful
end type
type cb_put from commandbutton within w_restful
end type
type cb_post from commandbutton within w_restful
end type
type cb_get from commandbutton within w_restful
end type
type sle_data from singlelineedit within w_restful
end type
type sle_url from singlelineedit within w_restful
end type
type st_2 from statictext within w_restful
end type
type st_1 from statictext within w_restful
end type
end forward

global type w_restful from window
integer width = 3186
integer height = 1980
boolean titlebar = true
string title = "PB请求RESTful的数据"
boolean controlmenu = true
boolean minbox = true
boolean maxbox = true
boolean resizable = true
long backcolor = 67108864
string icon = "AppIcon!"
boolean center = true
mle_resp mle_resp
st_3 st_3
cb_delete cb_delete
cb_put cb_put
cb_post cb_post
cb_get cb_get
sle_data sle_data
sle_url sle_url
st_2 st_2
st_1 st_1
end type
global w_restful w_restful

forward prototypes
public subroutine wf_https (string as_method)
end prototypes

public subroutine wf_https (string as_method);string ls_url,ls_data
ls_url = sle_url.text
ls_data = sle_data.text

string ls_ret 

ls_ret = gf_https_apex(ls_url,ls_data,as_method)

mle_resp.text = ls_ret
end subroutine

on w_restful.create
this.mle_resp=create mle_resp
this.st_3=create st_3
this.cb_delete=create cb_delete
this.cb_put=create cb_put
this.cb_post=create cb_post
this.cb_get=create cb_get
this.sle_data=create sle_data
this.sle_url=create sle_url
this.st_2=create st_2
this.st_1=create st_1
this.Control[]={this.mle_resp,&
this.st_3,&
this.cb_delete,&
this.cb_put,&
this.cb_post,&
this.cb_get,&
this.sle_data,&
this.sle_url,&
this.st_2,&
this.st_1}
end on

on w_restful.destroy
destroy(this.mle_resp)
destroy(this.st_3)
destroy(this.cb_delete)
destroy(this.cb_put)
destroy(this.cb_post)
destroy(this.cb_get)
destroy(this.sle_data)
destroy(this.sle_url)
destroy(this.st_2)
destroy(this.st_1)
end on

event resize;//窗口控件自动适用

long llw , llh
llw = this.workspacewidth( ) - sle_url.x 

llh = this.workspaceheight( ) - mle_resp.y

sle_url.width = llw

sle_data.width = llw

mle_resp.width = llw
mle_resp.height = llh
end event

type mle_resp from multilineedit within w_restful
integer x = 411
integer y = 248
integer width = 2158
integer height = 812
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "responseText"
borderstyle borderstyle = stylelowered!
end type

type st_3 from statictext within w_restful
integer x = 78
integer y = 256
integer width = 302
integer height = 76
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "Response:"
alignment alignment = Right!
boolean focusrectangle = false
end type

type cb_delete from commandbutton within w_restful
integer x = 14
integer y = 784
integer width = 375
integer height = 116
integer taborder = 60
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "DELETE"
end type

event clicked;//DELETE
wf_https("DELETE")
end event

type cb_put from commandbutton within w_restful
integer x = 14
integer y = 648
integer width = 375
integer height = 116
integer taborder = 50
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "PUT"
end type

event clicked;//PUT
wf_https("PUT")
end event

type cb_post from commandbutton within w_restful
integer x = 14
integer y = 512
integer width = 375
integer height = 116
integer taborder = 40
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "POST"
end type

event clicked;//POST
wf_https("POST")
end event

type cb_get from commandbutton within w_restful
integer x = 14
integer y = 376
integer width = 375
integer height = 116
integer taborder = 30
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
string text = "GET"
end type

event clicked;//GET
wf_https("GET")
end event

type sle_data from singlelineedit within w_restful
integer x = 411
integer y = 128
integer width = 2167
integer height = 100
integer taborder = 20
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "{}"
borderstyle borderstyle = stylelowered!
end type

type sle_url from singlelineedit within w_restful
integer x = 411
integer y = 4
integer width = 2167
integer height = 100
integer taborder = 10
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
string text = "https://apex.oracle.com/pls/apex/blma/b5217/"
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_restful
integer x = 137
integer y = 136
integer width = 242
integer height = 76
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "DATA:"
alignment alignment = Right!
boolean focusrectangle = false
end type

type st_1 from statictext within w_restful
integer x = 137
integer y = 28
integer width = 242
integer height = 76
integer textsize = -9
integer weight = 400
fontcharset fontcharset = ansi!
fontpitch fontpitch = variable!
fontfamily fontfamily = swiss!
string facename = "Tahoma"
long textcolor = 33554432
long backcolor = 67108864
string text = "URL:"
alignment alignment = Right!
boolean focusrectangle = false
end type

2 创建全局函数gf_https_apex()

用来发送请求和获得响应

global type gf_https_apex from function_object
end type

forward prototypes
global function string gf_https_apex (string as_url, string as_data, string as_method)
end prototypes

global function string gf_https_apex (string as_url, string as_data, string as_method);// 用WinHttp.WinHttpRequest.5.1组件,请求https网页和响应

/* 调用参数示例 
String ls_url,ls_data,ls_response
ls_url = 'https://datacenter-web.eastmoney.com/api/data/v1/get?'
ls_data = "callback=jQuery11230903969942572268_1651624511350&sortColumns=UPDATE_DATE,SECURITY_CODE&sortTypes=-1,-1&pageSize=50&pageNumber=1&reportName=RPT_LICO_FN_CPD&columns=ALL&filter=(REPORTDATE='2023-09-30')"
ls_response = gf_https_apex(ls_url,ls_data,ls_method)
*/

String ls_url,ls_data,ls_response

//请求的URL和数据
ls_url = as_url 
ls_data = as_data

OleObject lole_https   //声明ole
lole_https = CREATE oleobject 

long llr
any la
llr = lole_https.ConnectToNewObject("WinHttp.WinHttpRequest.5.1") 
lole_https.setTimeouts (50000,50000,50000,10000)
la = lole_https.open (as_method,ls_url, false)    //OPEN 

if not upper(as_method) = "DELETE" then 
	lole_https.setRequestHeader ("Content-Type", "application/json")
	lole_https.setRequestHeader ('Content-Length',string(len(ls_data)))
end if

lole_https.setRequestHeader ("charset","UTF-8")
lole_https.setRequestHeader ("User-Agent","Mozilla/5.0") //这个是Apex的RESTful需要的

lole_https.Send(ls_data) 
/*
关键是这一步:如果你的https的环境没有安装浏览器的认证的根证书,一定会报错退出,
如果你申请安装了verisign等权威机构发的根证书,用ie打开上面的https,就不会报红色警告(问你是不是继续)。
但pb不会提示你是不是继续,直接报错退出。verisign的证书一年好像要1万-10万元的服务费。在这里你如果想测试一下,
你可以把上面的https地址换成https://www.alipay.com/  (支付宝的),不会报错的。注意:这里的证书及验证都是单向验证,不是双向的。
*/

IF lole_https.Status >= 300 THEN 
	ls_response = string(lole_https.Status) + " : " + string(lole_https.StatusText)
	MessageBox ("HTTPs request failed:",ls_response ) 
	return ls_response
END IF 

blob lb_body
lb_body = lole_https.responseBody

ls_response = string(lb_body,EncodingUTF8!) //返回结果

//销毁 ole
destroy lole_https

return ls_response

end function

3 运行效果

窗口上的调用https请求的函数代码:

string ls_url,ls_data
ls_url = sle_url.text
ls_data = sle_data.text

string ls_ret 

ls_ret = gf_https_apex(ls_url,ls_data,as_method)

mle_resp.text = ls_ret

3.1 GET请求数据

【GET】按钮上的代码:

//GET
wf_https("GET")

在这里插入图片描述
数据库表上的数据:
在这里插入图片描述

3.2 POST添加数据

【POST】按钮上的代码:

//POST
wf_https("POST")

在这里插入图片描述
在这里插入图片描述

3.3 PUT修改数据

【PUT】按钮上的代码:

//PUT
wf_https("PUT")

在这里插入图片描述

3.4 DELETE删除数据

【DELETE】按钮上的代码:

//DELETE
wf_https("DELETE")


在这里插入图片描述

4 Apex的AutoREST的其它服务

  • GET一条记录
  • GET分页设置
  • 查询条件GET数据
  • 按查询条件DELETE数据
  • 批量从本地文件加载数据
  • 等等,不再举例演示了

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/155970.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

花 200 元测试 1300 个实时数据同步任务

背景 对于将数据作为重要生产资料的公司来说,超大规模的数据迁移同步系统( 1k、5k、10k 条同步任务)是刚需。 本文以此为出发点,介绍近期 CloudCanal 所做的一个容量测试:在单个 CloudCanal 集群上创建 1300 实时任务,验证系统是…

2023年中国骨质疏松治疗仪发展趋势分析:小型且智能将成为产品优化方向[图]

骨质疏松治疗仪利用磁场镇静止痛、消肿消炎的治疗作用迅速缓解患者腰背疼痛等骨质疏松临床症状。同时利用磁场的磁-电效应产生的感生电势和感生电流,改善骨的代谢和骨重建,通过抑制破骨细胞、促进成骨细胞的活性来阻止骨量丢失、提高骨密度。 骨质疏松治…

【软件推荐】我的常用Windows软件

文章目录 前言Colors Lite(颜色吸取)Everything(文件搜索)知云文献翻译Directory Opus(文件管理器)Snipaste(截图)AxMath(公式编辑器)Deskpin(窗口…

【Android】导入三方jar包/系统的framework.jar

1.Android.mk导包 1).jar包位置 与res和src同一级的libs中(没有就新建) 2).Android.mk文件 LOCAL_STATIC_ANDROID_LIBRARIES:android静态库,经常用于一些support的导包 LOCAL_JAVA_LIBRARIES:依赖的java库,一般为系统的jar…

Linux常用命令——bzcmp命令

在线Linux命令查询工具 bzcmp 比较两个压缩包中的文件 补充说明 bzcmp命令主要功能是在不真正解压缩.bz2压缩包的情况下,比较两个压缩包中的文件,省去了解压缩后在调用cmp命令的过程。 语法 bzcmp(参数)参数 文件1:指定要比较的第一个…

UE基础篇十:材质

导语: 视频文档在文末 虚幻引擎默认是延迟渲染(延迟渲染是通过先算出需要着色的像素,然后再迭代灯光,从而减少大量无效的灯光计算,来达到优化的目的) 一、基础知识 1.1 贴图分辨率尺寸 2的幂次方,长宽随意组合 非2的幂次方,不能设置MipMaps(引擎会生成多张分辨率更…

任务栏上的超萌小猫,实时显示CPU占用率,有趣.Net开源工具

推荐一个非常有趣的.Net开源小工具,它可以在电脑任务栏显示一只奔跑的小猫,实时显示CPU使用率! 01 项目简介 一款基于.NET 6.0运行环境的开源小工具,通过它,用户可以直观地查看CPU的使用情况,它会根据 CP…

程序员导航站

探路者 hello.alluniverse.vip 开发者导航 - Pro Developer网站导航 探路者是一款极简导航工具,致力于收录的每个站点都有其独特的作用。同时支持自定义导航,让用户快速实现个性化的导航站点。 特性概述 免费ChatGPT 装机必备 开发工具 Git精选项目 …

云计算(Docker)

Docker简介 Docker 是一个开源的应用容器引擎,基于 Go 语言,并遵从 Apache2.0 协议开源。它可以让开发者打包应用以及依赖包到一个轻量级、可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化。Docker 可用于开发…

2023年中国涂料树脂需求量、市场规模及行业竞争现状分析[图]

涂料用树脂是涂料的主要原材料,是涂料的主要成膜物,且了为涂料成品提供耐醇、耐磨、耐高温、耐高湿、减少涂料在涂装完成后的损耗、保持涂装后外观以及性状的稳定性等功能。 根据生产产品的性状不同,其下游产品,即涂料成品广泛应用…

锐捷EG易网关login.php以及其后台cli.php/branch_passw.php RCE漏洞复现 [附POC]

文章目录 锐捷EG易网关login.php以及其后台cli.php/branch_passw.php远程代码执行漏洞复现 [附POC]0x01 前言0x02 漏洞描述0x03 影响版本0x04 漏洞环境0x05 漏洞复现1.访问漏洞环境2.构造POC3.复现 锐捷EG易网关login.php以及其后台cli.php/branch_passw.php远程代码执行漏洞复…

电脑集中管理软件有哪些?电脑集中管控怎么做

电脑集中管理软件有哪些?电脑集中管控怎么做 电脑集中管理软件是指通过一种软件或系统,对多台电脑进行集中管理和控制的工具。这种软件通常具备远程控制、软硬件监控、自动部署等功能。可以方便企业或组织统一管理电脑资源,提高工作效率。今…

java“贪吃蛇”小游戏

基于java实现贪吃蛇小游戏,主要通过绘制不同的图片并以一定速度一帧一帧地在窗体上进行展示。 我是在javaSwing项目下创建了一个包 名字叫做:Snakes包 包下有一个启动类和一个设置代码的主界面两个类 代码主界面: 代码主界面主要讲解的是 …

linux关于cmake,makefile和gdb的使用

c文件的编译 安装环境(centos 7) 检查命令是否齐全 gcc --version g --version gdb–version 安装命令 yum -y install gcc-c安装g命令(用于编译c/c文件) yum -y install gcc安装gcc命令(用于编译c文件) 每个都出现版本号,证明…

Java-接口和抽象类

本章重点:1. 抽象类 2. 接口 3.Object类 1. 抽象类 1.1 抽象类概念 在面向对象的概念中,所有的对象都是通过类来描绘的,但是反过来,并不是所有的类都是用来描绘对象的,如果一个类中没有包含足够的信息来描绘一…

计算机毕业设计项目选题推荐(免费领源码)java+mysql二手校园交易平台67613

目录 摘要 1 绪论 1.1 研究背景 1.2国内外研究现状 1.3论文结构与章节安排 2 二手校园交易平台系统分析 2.1 可行性分析 2.2 系统流程分析 2.2.1 数据流程 3.3.2 业务流程 2.3 系统功能分析 2.3.1 功能性分析 2.3.2 非功能性分析 2.4 系统用例分析 2.5本章小结 …

滚雪球学Java(09-2):Java中的关系运算符,你真的掌握了吗?

咦咦咦,各位小可爱,我是你们的好伙伴——bug菌,今天又来给大家普及Java SE相关知识点了,别躲起来啊,听我讲干货还不快点赞,赞多了我就有动力讲得更嗨啦!所以呀,养成先点赞后阅读的好…

3.6 Windows驱动开发:内核进程汇编与反汇编

在笔者上一篇文章《内核MDL读写进程内存》简单介绍了如何通过MDL映射的方式实现进程读写操作,本章将通过如上案例实现远程进程反汇编功能,此类功能也是ARK工具中最常见的功能之一,通常此类功能的实现分为两部分,内核部分只负责读写…

C语言每日一题(31)相交链表

力扣160.相交链表 题目描述 给你两个单链表的头节点 headA 和 headB ,请你找出并返回两个单链表相交的起始节点。如果两个链表不存在相交节点,返回 null 。 图示两个链表在节点 c1 开始相交: 题目数据 保证 整个链式结构中不存在环。 注意…