[高手]请教如何用wininet实现https协议上传文件?

summerhill 2004-01-07 03:06:13
请高手指教!
还有象https协议中要注意一些什么东西?
...全文
295 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
iamluodong 2004-01-18
  • 打赏
  • 举报
回复
使用wininet实现,就我感觉,winnet由于使用了IE的技术,文件处理由于涉及到安全性的问题,所以够呛。
summerhill 2004-01-17
  • 打赏
  • 举报
回复
iamluodong(嗨) :我这里有winsock通过http协议的代码,但没有https的,好像很麻烦的说,所以我想用wininet实现。
summerhill 2004-01-17
  • 打赏
  • 举报
回复
chenkangli(编程浪子) : 你的代码不能运行啊,错误提示找不到wininet的接入口。
iamluodong 2004-01-17
  • 打赏
  • 举报
回复
通过socket我知道怎么做。
goldensai 2004-01-14
  • 打赏
  • 举报
回复
chenkangli(编程浪子) :
你贴出来的代码,好像还是不能传文件吧.虽然用了post方法,但还是没有传送消息体呀!
传送消息体要用httpsendrequestex才行吧!
chenkangli 2004-01-14
  • 打赏
  • 举报
回复
『vb调用wininet api接口post数据到指定的url』

注释:this module is called modwininet.bas. use the splitaddr() function to get the address in the correct format for postinfo.

option explicit

注释:author: sam huggill
注释:email: sam@vbsquare.com

private declare function internetopen lib "wininet.dll" _
alias "internetopena" _
(byval lpszcallername as string, _
byval dwaccesstype as long, _
byval lpszproxyname as string, _
byval lpszproxybypass as string, _
byval dwflags as long) as long

private declare function internetconnect lib "wininet.dll" _
alias "internetconnecta" _
(byval hinternetsession as long, _
byval lpszservername as string, _
byval nproxyport as integer, _
byval lpszusername as string, _
byval lpszpassword as string, _
byval dwservice as long, _
byval dwflags as long, _
byval dwcontext as long) as long

private declare function internetreadfile lib "wininet.dll" _
(byval hfile as long, _
byval sbuffer as string, _
byval lnumbytestoread as long, _
lnumberofbytesread as long) as integer

private declare function httpopenrequest lib "wininet.dll" _
alias "httpopenrequesta" _
(byval hinternetsession as long, _
byval lpszverb as string, _
byval lpszobjectname as string, _
byval lpszversion as string, _
byval lpszreferer as string, _
byval lpszaccepttypes as long, _
byval dwflags as long, _
byval dwcontext as long) as long

private declare function httpsendrequest lib "wininet.dll" _
alias "httpsendrequesta" _
(byval hhttprequest as long, _
byval sheaders as string, _
byval lheaderslength as long, _
byval soptional as string, _
byval loptionallength as long) as boolean

private declare function internetclosehandle lib "wininet.dll" _
(byval hinternethandle as long) as boolean

private declare function httpaddrequestheaders lib "wininet.dll" _
alias "httpaddrequestheadersa" _
(byval hhttprequest as long, _
byval sheaders as string, _
byval lheaderslength as long, _
byval lmodifiers as long) as integer


public function postinfo$(srv$, port$, script$, postdat$)

dim hinternetopen as long
dim hinternetconnect as long
dim hhttpopenrequest as long
dim bret as boolean

hinternetopen = 0
hinternetconnect = 0
hhttpopenrequest = 0

注释:use registry access settings.
const internet_open_type_preconfig = 0
hinternetopen = internetopen("http generic", _
internet_open_type_preconfig, _
vbnullstring, _
vbnullstring, _
0)

if hinternetopen <> 0 then
注释:type of service to access.
const internet_service_http = 3
const internet_default_http_port = 80
注释:change the server to your server name
hinternetconnect = internetconnect(hinternetopen, _
srv$, _
port$, _
vbnullstring, _
"http/1.0", _
internet_service_http, _
0, _
0)

if hinternetconnect <> 0 then
注释:brings the data across the wire even if it locally cached.
const internet_flag_reload = &h80000000
hhttpopenrequest = httpopenrequest(hinternetconnect, _
"post", _
script$, _
"http/1.0", _
vbnullstring, _
0, _
internet_flag_reload, _
0)

if hhttpopenrequest <> 0 then
dim sheader as string
const http_addreq_flag_add = &h20000000
const http_addreq_flag_replace = &h80000000
sheader = "content-type: application/x-www-form-urlencoded" _
& vbcrlf
bret = httpaddrequestheaders(hhttpopenrequest, _
sheader, len(sheader), http_addreq_flag_replace _
or http_addreq_flag_add)

dim lpszpostdata as string
dim lpostdatalen as long

lpszpostdata = postdat$
lpostdatalen = len(lpszpostdata)
bret = httpsendrequest(hhttpopenrequest, _
vbnullstring, _
0, _
lpszpostdata, _
lpostdatalen)

dim bdoloop as boolean
dim sreadbuffer as string * 2048
dim lnumberofbytesread as long
dim sbuffer as string
bdoloop = true
while bdoloop
sreadbuffer = vbnullstring
bdoloop = internetreadfile(hhttpopenrequest, _
sreadbuffer, len(sreadbuffer), lnumberofbytesread)
sbuffer = sbuffer & _
left(sreadbuffer, lnumberofbytesread)
if not cbool(lnumberofbytesread) then bdoloop = false
wend
postinfo = sbuffer
bret = internetclosehandle(hhttpopenrequest)
end if
bret = internetclosehandle(hinternetconnect)
end if
bret = internetclosehandle(hinternetopen)
end if
end function

public sub splitaddr(byval addr$, srv$, script$)
注释:inputs: the full url including http://
注释: two variables that will be changed
注释:
注释:returns: splits the addr$ var into the server name
注释: and the script path

dim i%

i = instr(addr$, "/")
srv$ = mid(addr$, i + 2, len(addr$) - (i + 1))
i = instr(srv$, "/")
script$ = mid(srv$, i, len(srv$) + 1 - i)
srv$ = left$(srv$, i - 1)

end sub

你看看.
goldensai 2004-01-14
  • 打赏
  • 举报
回复
还是我来顶顶吧!不过好像效果不大
summerhill 2004-01-12
  • 打赏
  • 举报
回复
up~~~~~~~~~
内容概要:本文围绕“单相逆变器闭环逆变电路PWM模型仿真研究”展开,基于Simulink平台构建单相逆变器的闭环控制系统仿真模型,重点研究PWM调制技术在逆变电路中的应用与实现。文中详细阐述了系统架构设计、电压电流双闭环控制策略的实现原理、控制器参数设计及仿真建模全过程,并通过仿真结果验证了控制方案在动态响应、稳态精度与系统稳定性方面的有效性。同时,文档还涵盖多种电力电子系统典型应用场景,如多类型短路故障仿真(中性点不接地、经小电阻接地、经消弧线圈接地等)、软开关技术、微电网能量管理、MPPT控制等,体现出较强的技术综合性和工程实践价值。; 适合人群:电气工程、自动化、电力电子与新能源等相关专业的高校本科生、研究生、科研人员,以及从事电力系统仿真、逆变器设计与新能源并网技术研发的工程技术人员。; 使用场景及目标:①掌握基于Simulink的单相逆变器闭环控制系统建模与PWM仿真方法;②深入理解双闭环控制、SPWM/SVPWM调制、系统稳定性分析等核心技术原理;③为课程设计、毕业设计、科研项目或实际工程开发提供可复用的仿真模型与技术支持; 阅读建议:建议结合文中仿真模型动手实践,重点掌握PI控制器参数整定、PWM信号生成机制与仿真结果分析方法,同时可延伸学习文档中涉及的软开关、故障仿真、微电网控制等关联技术,以拓展系统级设计能力。

1,502

社区成员

发帖
与我相关
我的任务
社区描述
VB 网络编程
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧