'm stumped why this doesn't work can't seem to find any problems.

Here is the code.

vb Code:
  1. Public Const MULTIPART_BOUNDARY = "speed"
  2. Function getBalance() As String
  3. Dim sEntityBody As String
  4. Dim postBody() As Byte
  5. Dim username As String
  6. Dim password As String
  7.  
  8. username = CStr(frmMain.txtUser.text)
  9. password = CStr(frmMain.txtPass.text)
  10.  
  11. sEntityBody = "--" & MULTIPART_BOUNDARY & vbCrLf
  12. sEntityBody = sEntityBody & "Content-Dispostion: form-data; name=""function""" & vbCrLf & vbCrLf & "balance" & vbCrLf
  13. sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
  14. sEntityBody = sEntityBody & "Content-Dispostion: form-data; name=""username""" & vbCrLf & vbCrLf & username & vbCrLf
  15. sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & vbCrLf
  16. sEntityBody = sEntityBody & "Content-Dispostion: form-data; name=""password""" & vbCrLf & vbCrLf & password & vbCrLf
  17. sEntityBody = sEntityBody & "--" & MULTIPART_BOUNDARY & "--" & vbCrLf
  18.  
  19. postBody = StrConv(sEntityBody, vbFromUnicode)
  20.  
  21. Dim xhr As Object
  22. Set xhr = CreateObject("WinHttp.WinHttpRequest.5.1")
  23. xhr.Option(WinHttpRequestOption_EnableRedirects) = False
  24. If xhr Is Nothing Then Set xhr = CreateObject("WinHttp.WinHttpRequest")
  25. If xhr Is Nothing Then Set xhr = CreateObject("MSXML2.ServerXMLHTTP")
  26. If xhr Is Nothing Then Set xhr = CreateObject("Microsoft.XMLHTTP")
  27. xhr.open "POST", "http://poster.example.com", False
  28.  
  29. xhr.setRequestHeader "User-Agent", "Alalala"
  30. xhr.setRequestHeader "Content-Type", "multipart/form-data; boundary=" & MULTIPART_BOUNDARY
  31. xhr.setRequestHeader "Content-Length", Len(sEntityBody)
  32. xhr.send "" + sEntityBody 'postBody 'URLEncode(sEntityBody)
  33.  
  34.     If xhr.Status = 200 Then
  35.         getBalance = xhr.responseText
  36.     Else
  37.         frmMain.addToChatbox "Failed at getting response from blah ErrCode:" & xhr.Status
  38.     End If
  39. End Function

This is the form I want to duplicate.

vb Code:
  1. <form
  2.  method="post"
  3.  action="http://poster.example.com/"
  4.  enctype="multipart/form-data">
  5.  <input type="hidden" name="function" value="balance">
  6.  <input type="text"   name="username" value="blah">
  7.  <input type="text"   name="password" value="blah">
  8.  <input type="submit" value="Send">
  9. </form>

Here is the send/response from sniffing.

Here is a packet sniff. (Altered the host etc to example after)

Code:
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--..
double dots means vbCrLf, in case someone doesn't understand

response is empty

Code:
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....
For some reason I don't see any problems with the code I mimic that comes from firefox packet sniffing yet I don't get returned a blank page wth?,
Only difference is firefox/chrome sends 2 packets one with the header and the other with the attachment/parameters.. and my method sends in one single packet, shouldn't be a problem though as I've seen imageshack uploaders here in the codebank that do the same except thing..

Can someone spot what I am doing wrong please, thank you.