gpt4 book ai didi

vb6 - Post 方法 + WinHttpRequest + multipart/form-data

转载 作者:行者123 更新时间:2023-12-01 07:46:19 25 4
gpt4 key购买 nike

我很难过为什么这不起作用似乎找不到任何问题。

这是代码。

Public Const MULTIPART_BOUNDARY = "speed"
Function getBalance() As String
Dim sEntityBody As String
Dim postBody() As Byte
Dim username As String
Dim password As String

username = CStr(frmMain.txtUser.text)
password = CStr(frmMain.txtPass.text)

sEntityBody = "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""function""" & vbCrLf & vbCrLf & "balance" & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""username""" & vbCrLf & vbCrLf & username & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
sEntityBody = sEntityBody & "Content-Disposition: form-data; name=""password""" & vbCrLf & vbCrLf & password & vbCrLf
sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & "--" & vbCrLf

postBody = StrConv(sEntityBody, vbFromUnicode)

Dim xhr As Object
Set xhr = CreateObject("WinHttp.WinHttpRequest.5.1")
xhr.Option(WinHttpRequestOption_EnableRedirects) = False
If xhr Is Nothing Then Set xhr = CreateObject("WinHttp.WinHttpRequest")
If xhr Is Nothing Then Set xhr = CreateObject("MSXML2.ServerXMLHTTP")
If xhr Is Nothing Then Set xhr = CreateObject("Microsoft.XMLHTTP")
xhr.open "POST", "http://poster.example.com", False

xhr.setRequestHeader "User-Agent", "Alalala"
xhr.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & MULTIPART_BOUNDARY
xhr.setRequestHeader "Content-Length", Len(sEntityBody)
xhr.send "" + sEntityBody 'postBody 'URLEncode(sEntityBody)

If xhr.Status = 200 Then
getBalance = xhr.responseText
Else
frmMain.addToChatbox "Failed at getting response from blah ErrCode:" & xhr.Status
End If
End Function

现在下面的工作(虽然它只是一个 HTML 表单)。
<form 
method="post"
action="http://poster.example.com/"
enctype="multipart/form-data">
<input type="hidden" name="function" value="balance">
<input type="text" name="username" value="blah">
<input type="text" name="password" value="blah">
<input type="submit" value="Send">
</form>

这是一个数据包嗅探。 (将主机等更改为示例之后)

POST / HTTP/1.1..User-Agent: Alalala..Content-Type: multipart/form-data; boundary=speed..Content-Length: 233..Accept: /..Host: poster.example.com..Connection: Keep-Alive....--speed..Content-Dispostion: form-data; name="function"....balance..--speed..Content-Dispostion: form-data; name="username"....blah..--speed..Content-Dispostion: form-data; name="password"....blah..--speed--..



回复为空

HTTP/1.1 200 OK..Date: Thu, 07 Oct 2010 20:31:20 GMT..Server: Apache..Content-Length: 0..Connection: close..Content-Type: text/html; charset=UTF-8....



P.S.> 不必发送带有值 Send 的提交按钮,所以如果有人想知道,那就不是它了。
它可能是什么,我从嗅探中注意到,它将 header + 发布数据(上传数据)作为一个数据包发送,而 firefox/chrome 将其作为 2 个单独的数据包发送。


谢谢

最佳答案

拼写错误 内容配置必须是 内容配置是的,多亏了我已经受苦了 6?也许7个小时。
终于解决了

关于vb6 - Post 方法 + WinHttpRequest + multipart/form-data,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3885703/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com