1

I am trying to post an xml file (utf-16 encoded) using curl to a REST service. The REST service is expecting 'multipart/form-data' content type.

Curl Script: curl -k -i -H "Content-Type=multipart/form-data" -F "[email protected];type=text/xml" -X POST -u :

However, i am getting 500 Internal Server error while running the script.

Response: <= Recv header, 23 bytes (0x17) 0000: HTTP/1.1 100 Continue <= Recv header, 36 bytes (0x24) 0000: HTTP/1.1 500 Internal Server Error

Through chrome's add on 'postman app' i am able to successfully post the xml to the REST service.

Unable to figure out the issue causing the 500 error. Kindly help me in resolving this issue.

Regards Anooja

1 Answer 1

1

First some nitpicks on your command line:

  1. The Content-Type header you provide is wrong, the name/contents should be separated with a colon.
  2. You shouldn't even need that -H as -F sets that content-type on its own
  3. The "-X POST" is superfluous as -F will use a POST already

Then, add --trace or --trace-ascii to the command line to capture the entire request, and then you capture the entire working request you do with chrome and then you compare. Where there are differences, you adjust the curl command line to be more like the browser version. Re-iterate until it works.

Sign up to request clarification or add additional context in comments.

2 Comments

Hi Daniel, I tried the below curl command, however still getting the 500 server error. curl -k -i --trace-ascii dump.txt -F '[email protected];type=text/plain' -u <username>:<password> <endPointURL> Also the request using curl and postman looks the same. Pasting the request as another comment below. Please let me know what could be the issue.
curl request: 013e: Content-Type: multipart/form-data; boundary=------------------ 017e: --------d485140609e1 0194: <= Recv header, 23 bytes (0x17) 0000: HTTP/1.1 100 Continue => Send data, 138 bytes (0x8a) 0000: ------------------------------d485140609e1 002c: Content-Disposition: form-data; name="file"; filename="file.txt" 006e: Content-Type: text/plain Bowser request: Content-Type: multipart/form-data Cache-Control: no-cache ----WebKitFormBoundaryE19zNvXGzXaLvS5C Content-Disposition: form-data; name="file"; filename="file.txt" Content-Type: text/plain ----WebKitFormBoundaryE19zNvXGzXaLvS5C

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.