8

I'm struggling with creating POST multipart/mixed request with Postman Chrome extension. I keep getting HTTP 500.

Already gone through this question, but sadly solution doesn't works for me.

Here is my curl request which works for me.

curl -H "Content-Type: multipart/form-data" -F "merchantLogo=@offerlogo-320-320.png; type=image/png" -F "merchantDetails=@merchant.json; type=application/json" -X PATCH localhost:5000/api/merchants/57035bda0c74362faf5937f2/details -i -v

And when I use Postman enter image description here

I am getting such response

{"code": 500,
"message": "There was an error processing your request. It has been logged (ID 034bec7815baca2e)."}

Request headers being passed from postman. Request headers from Postman

Somehow, the merchantDetails are always being passed as null when calling from POSTMAN and is passed properly when making call from curl.

Any help would be much appreciated.

EDITED 1:

My request from POSTMAN copied as curl,

curl 'http://localhost:5000/api/merchants/5714d8e060b2a79e62227d1a/details' -X PATCH -H 'Pragma: no-cache' -H 'Origin: chrome-extension://fdmmgilgnpjigdojojpjoooidkmcomcm' -H 'Accept-Encoding: gzip, deflate, sdch' -H 'Accept-Language: en-GB,en-US;q=0.8,en;q=0.6' -H 'User-Agent: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36' -H 'Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryxRZ6VKzFV40ZFIsd' -H 'Accept: /' -H 'Cache-Control: no-cache' -H 'Cookie: JSESSIONID=1ofut8bbydk491k2s80i4rowed; JSESSIONID=yg4l9zpjs5oj1xaqnuo44ehp6' -H 'Connection: keep-alive' --data-binary $'------WebKitFormBoundaryxRZ6VKzFV40ZFIsd\r\nContent-Disposition: form-data; name="merchantDetails"; filename="merchant.json"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n------WebKitFormBoundaryxRZ6VKzFV40ZFIsd\r\nContent-Disposition: form-data; name="merchantLogo"; filename="offerlogo-320-320.png"\r\nContent-Type: image/png\r\n\r\n\r\n------WebKitFormBoundaryxRZ6VKzFV40ZFIsd--\r\n' --compressed

Community
  • 1
  • 1
Aditya
  • 1,334
  • 1
  • 12
  • 23
  • Could you try opening up Chrome Developer Tools and open up the network tab and include the request headers that were sent when you clicked "Send"? – Kirk Woll Apr 11 '16 at 14:03
  • @KirkWoll Added request headers being sent – Aditya Apr 12 '16 at 13:20
  • Honestly, I hadn't responded 'cause I was kind of stumped. But try this: with Chrome Developer Tools open, and the network tab open, after making the request in Postman, right-click on the request in the network tab and choose "Copy as cURL (bash)" and edit your question to include that data. That might give us a good apples to apples comparison between the curl command that works and the one that doesn't. (though honestly not sure how that copy command will work with file attachment data...) – Kirk Woll Apr 16 '16 at 23:04
  • Also, the server you are using -- does it have any verbose logging option? It is clearly failing to accept your Postman command and the reasons remain unclear. Your headers look great, but ideally the server would provide some details of what precisely was wrong with your request. Also, what Http Method are you using? I assume PATCH? (wasn't visible in the screenshot) – Kirk Woll Apr 16 '16 at 23:13
  • @KirkWoll Added the postman request being copied as curl. It seems that problem is with ContentType of json file being passed which is application/octet-stream. But it should be application/json. – Aditya Apr 18 '16 at 12:58
  • Yes, my request is PATCH, and yes the server also has verbose logging option but the problem is that merchantDetails being passed from request are null, hence I get a NullPointerException – Aditya Apr 18 '16 at 13:00
  • Hmm, I Postman on both my Mac and Windows. Windows passed `application/octet-stream` and the Mac passed `application/json`. Not sure why that's behaving differently -- my hunch is that Chrome is the one supplying the content-type and it behaves differently on different OSs. Is there anything you can do on the server to make it less strict about the content-types of the form parts? – Kirk Woll Apr 18 '16 at 13:28
  • I don't want to make my API less strict only because POSTMAN doesn't works for me. This seems to be issue on [POSTMAN](https://github.com/postmanlabs/postman-app-support/issues/1991#issuecomment-214580096). Since curl works fine for me. – Aditya Apr 30 '16 at 11:22
  • This seems to be bug(or unsupported feature) in POSTMAN, I have raised [this](https://github.com/postmanlabs/postman-app-support/issues/1991) long ago, but still no success. – Aditya Sep 14 '16 at 14:02

0 Answers0