Question:
I am currently trying to create a webrequest that matches a third party's example. I have found that the ActiveX HTTP object will create a request where addheader will add HTTP headers and addparam will add HTTP(or MIME) parameters. I am not sure if I am missing something in the Chilkat reference materials or not. When I test the request, I get a HTTP 500 error back from the third party's server. The third party's example has Content-Type and Content-Transfer-Encoding on each of its parameters. Also, this could play a role because one of the parameters is a file sent in binary. The rest of the parameters are plain text. The third party also puts the host name in the POST line and adds an additional value to the Content-Disposition element that states the file name being uploaded. I'm not sure how to have Chilkat HTTP to do any of that. I am using Visual FoxPro 9.0 and the ActiveX Chilkat component (The new 9.5.0 single dll).
Here is the request I am sending (values changed to protect data of course) per the Chilkat log:
POST /Putting/Files/In/APathSomewhere.html HTTP/1.1
Content-Type: multipart/form-data; boundary=------------060900060309090107080400
Accept: application/zip
Accept-Language: en-us
Cookie: SMCHALLENGE=YES
Authorization: Basic AAAAAAAAAAAAAAAAAAAAAAAAAA=
Host: test.somewebsite.com
Content-Length: 43839
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable1"
Variable1Value
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable2"
Variable2Value
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable3"
Variable3Value
--------------060900060309090107080400
Content-Disposition: form-data; name="UploadFile"
BinaryFileCharactersHere
Here is what the third party is saying a valid example is:
POST https://test.somewebsite.com/Putting/Files/In/APathSomewhere.html HTTP/1.1
Content-Type: multipart/form-data; boundary="------------060900060309090107080400"
Accept: application/zip
Accept-Language: en-us
Cookie: SMCHALLENGE=YES
Authorization: Basic AAAAAAAAAAAAAAAAAAAAAAAAAA=
Content-Length: 43839
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable1"
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Variable1Value
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable2"
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Variable2Value
--------------060900060309090107080400
Content-Disposition: form-data; name="Variable3"
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Variable3Value
--------------060900060309090107080400
Content-Type: application/zip; name=SomeFile.xml.gz
Content-Transfer-Encoding: binary
Content-Disposition: form-data; name="UploadFile"; filename="SomeFile.xml.gz"
BinaryFileCharactersHere
If the data in the HttpRequest object is added as parameters (via the HttpRequest.AddParam method), then you'll get what you are currently sending:
... --------------060900060309090107080400 Content-Disposition: form-data; name="Variable1"Variable1Value --------------060900060309090107080400 Content-Disposition: form-data; name="Variable2"
Variable2Value ...
If you add the data as "files" to be uploaded, then you'll produce an HTTP request with the additional headers. Instead of calling AddParam, call the AddBytesForUpload2 method for binary data, and AddStringForUpload2 method for text data. These methods allow for you to explicitly specify the content-type.