Question:
Hey guys.
Could you tell me how to make a http multipart request with Chilkat?
Wireshark shows me that I have to send the following header:
Content-Type: multipart/form-data; boundary=---------------------------26204304919913
but I can not set ContentType to this string value, because Chilkat cuts the real content type at ";"
So this code is not working:
Chilkat.HttpRequest req = new Chilkat.HttpRequest();
req.HttpVerb = WebRequestMethods.Http.Post;
req.AddHeader("Content-Type", "multipart/form-data; boundary=---------------------------"+ boundary);
AddHeader or set ContentType are both not working.
How can I solve the problem?
BlackMatrix
HTTP requests and responses are MIME. Understanding MIME is key to understanding that it makes no difference that the boundary string is continued on the next line. MIME headers may be split into several lines. A line that begins with a SPACE or TAB character is a continuation of the current header field. Therefore, the following two lines are completely equivalent:
Content-Type: multipart/form-data; boundary=---------------------------26204304919913
is 100% equivalent to
Content-Type: multipart/form-data; boundary=---------------------------26204304919913
Also, there is no need to explicitly specify a boundary string because it will automatically be generated based on the fact that the Content-Type is "multipart/form-data". Therefore, the only thing you should need to do is to set the ContentType property equal to "multipart/form-data".
Thanks.
And how do I add parameters then? With the normal HttpWebRequest I did the following to create my poststring:
var postStringBuilder = new StringBuilder();
postStringBuilder.AppendLine("-----------------------------" + boundary);
postStringBuilder.AppendLine("Content-Disposition: form-data; name=\"step\"");
postStringBuilder.AppendLine();
postStringBuilder.AppendLine("1");
So with Chilkat I only have to this?
Chilkat.HttpRequest req = new Chilkat.HttpRequest();
req.HttpVerb = WebRequestMethods.Http.Post;
req.ContentType="multipart/form-data";
req.AddHeader("step","1");
Edit: Yes, its working.