Archived Forum Post

Index of archived forum posts


Chilkat c# - make a http request with boundary

Apr 19 '13 at 10:08

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?


Accepted Answer

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; 

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



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\"");

So with Chilkat I only have to this?

        Chilkat.HttpRequest req = new Chilkat.HttpRequest();
        req.HttpVerb = WebRequestMethods.Http.Post;

Edit: Yes, its working.