我很难理解为什么这不起作用,似乎找不到任何问题。
这是密码。
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..用户代理:
alalala..内容类型:
多部分/表格数据;
边界=速度..内容长度:
233、接受:
/
..host:poster.example.com..connection:
保持活力….--速度..内容处理:表单数据;
name=“function”….平衡….--速度..内容处理:
表格数据;
name=“用户名”…blah….--速度..内容处理:
表格数据;
name=“password”…blah….--速度--.
响应为空
http/1.1 200好的..日期:10月7日星期四
2010年20:31:20格林尼治标准时间。服务器:
apache..内容长度:0..连接:
关闭..内容类型:文本/html;
字符集=utf-8….
P.S.>不必发送带有值send的“提交”按钮,因此如果有人想知道,就不必发送。
我从嗅探中注意到的是,它以一个包的形式发送头+后数据(上传数据),而firefox/chrome则以两个单独的包的形式发送。
谢谢你