-1

I have a problem with sending a POST request through WebClient in C# API. The POST request is:

POST http://aaa.com/login.php HTTP/1.1
Host: www.aaa.com
Connection: keep-alive
Content-Length: 346
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://www.aaa.com
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.22 (KHTML, like Gecko) Chrome/25.0.1364.152 Safari/537.22
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryK0J3zdRYpjgldAFy
Referer: http://www.turbotrafficbooster.com/
Accept-Encoding: gzip,deflate,sdch
Accept-Language: bg-BG,bg;q=0.8
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.3
Cookie: PHPSESSID=b703525853495c9257b3f3ec579c937a

------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="navaction"

login
------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="UserID"

test
------WebKitFormBoundaryK0J3zdRYpjgldAFy
Content-Disposition: form-data; name="Password"

test
------WebKitFormBoundaryK0J3zdRYpjgldAFy--

I know what to do with the headers like user-agent and etc., but I have a problem with the boundaries. I don't know how to put them and where to do it..

abatishchev
  • 98,240
  • 88
  • 296
  • 433
  • What code are you using to build this request? – Tim S. Van Haren Mar 11 '13 at 20:31
  • Are you even required to add the `boundary` header element? Did you just copy and paste someone else's header? Have a look at this post too: http://stackoverflow.com/questions/2305218/what-is-the-boundary-parameter-in-an-http-multi-part-post-request – atconway Mar 11 '13 at 20:37
  • Use Fiddler and perform the same action in IE. You should be able to see how the form data is submitted from the trace and copy the format. – JamieSee Mar 11 '13 at 20:40
  • [This](http://stackoverflow.com/a/2035273/298754) might be relevant too, but I couldn't figure out how to work that into my answer. – Bobson Mar 11 '13 at 20:42

1 Answers1

0

See this answer and the examples in the linked specification here. Example:

  Content-Type: multipart/form-data; boundary=AaB03x

  --AaB03x   
  Content-Disposition: form-data; name="submit-name"

  Larry   
  --AaB03x

WebKitFormBoundaryK0J3zdRYpjgldAFy is just a convention. It could be MyFoobaredBoundry if you want, provided that that you declare and close it off appropriately. Different browsers use different strings, so nothing on the receiving end should differentiate because of it.

However, this is probably not something you have to do yourself...

Community
  • 1
  • 1
Bobson
  • 13,498
  • 5
  • 55
  • 80