vb6 - Post Method + WinHttpRequest + multipart/form-data -


i'm stumped why doesn't work can't seem find problems.

here code.

public const multipart_boundary = "speed" function getbalance() string dim sentitybody string dim postbody() byte dim username string dim password 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 object set xhr = createobject("winhttp.winhttprequest.5.1") xhr.option(winhttprequestoption_enableredirects) = false if xhr nothing set xhr = createobject("winhttp.winhttprequest") if xhr nothing set xhr = createobject("msxml2.serverxmlhttp") if xhr nothing 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         getbalance = xhr.responsetext     else         frmmain.addtochatbox "failed @ getting response blah errcode:" & xhr.status     end if end function 

now below works (although it's html form).

<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> 

here packet sniff. (altered host etc example after)

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--..

response empty

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.> submit button value send doesn't have sent thats not if wondering. , i've noticed sniffing sends header + post data (upload data) 1 packet , firefox/chrome sends 2 seperate packets.

thank you

mis-spelled content-dispostion has content-disposition yup i've been suffering 6? maybe 7 hours.

solved finally


Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -