How to send file with POST request using curl? - api

I am trying to send a file using the POST request, with curl:
curl -v -u admin:admin -X POST -H 'Content-Type: application/xml' --data-binary '#test.xml' 'http://localhost:10215/'
I am getting the following errors:
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: application
* Closing connection 0
curl: (6) Could not resolve host: application
Note: Unnecessary use of -X or --request, POST is already inferred.
* Could not resolve host: 'http
* Closing connection 1
curl: (6) Could not resolve host: 'http
Over Postman, I managed to send the file, by adding the file content in the body of the request. But how could I update the curl command, so that I could be able to send the file from the folder I am running the command from? The authentication is basic authentication and the Content-Type of the request must be specified.

If you have achieve it with postman, just copy the curl code that is generated by postman clicking in the code button:

Related

Works in curl (and Rested API Client) but not in Postman?

I am able to login my local (and remote server) with the following curl (which I generated using Postman)... and I can login successfully using another API Client (Rested) with the same params/headers/body that I am trying to use in Postman. I've turned off "SSL cert verification" and "Send Postman Token header" in settings (per other Stack Overflow answers).. but still getting an unauthorized response from server when using Postman (but not when using curl or Rested)
curl:
curl -X POST \ http://localhost:8080/api/user/login \ -H 'Accept:
application/json' \ -H 'Content-Type: application/json' \ -d '{
"email": "email#example.com",
"password": "examplemail**" }'
And here is my log..
I just solved my own Q.. and posting this answer because I've seen other questions re: curl working but postman not on SO and Postman communities. My solution was to check the Content-Length header and Connection headers. They were auto populating anyway, so after 'accepting' them as headers, the Postman request worked. Here is a screenshot of the headers that worked.

cURL vs Postman, different responses to HTTPS POST

We are setting up a reporting feed to a client and, in testing out the endpoint, we are receiving different responses between cURL (command-line) and Postman. In Postman, the request goes through, just fine; we get a 200-OK back. However, when we send the request in cURL, we get the following response back curl: (60) SSL certificate problem: certificate has expired
With cURL
The cURL request looks like the following:
curl -i -H "content-type: application/json" -d '{"foo": [],"bar": [],"baz": []}' https://test.example.com/notARealEndpoint
With Postman
The Postman setup is hard to display, but it's code-conversion looks like:
cURL interpretation
curl --location --request POST 'https://test.example.com/not/aReal/Endpoint' --header 'Content-Type: application/json' --header 'Content-Type: text/plain' --data-raw '{"foo": [],"bar": [],"baz": []}'
*This, by the way, returns the same certificate has expired error when run in command line
HTTP interpretation
POST /not/aReal/Endpoint HTTP/1.1
Host: test.example.com
Content-Type: application/json
Content-Type: text/plain
{"foo": [],"bar": [],"baz": []}
Looks like the target server has an expired SSL certificate. The reason that postman is not raising an error couble be because of disabled SSL verification checks.
You can disable those checks in curl by using a --insecure or -k option.
eg:
curl https://expired.badssl.com
Will throw the same error that you are seeing.
versus
curl --insecure https://expired.badssl.com
will return an html response body.

How do I solve this RabbitMQ REST call 415 response issue?

In the code I inherited there is a REST call that sets up user permissions for a virtual host in a rabbitmq installation. On my developer box I have latest RabbitMQ server installed, 3.7.7. The client software uses a Spring RestTemplate to query the host. It generates a PUT request to http://localhost:15672/api/permissions/myhost/administrator with a payload of
{"read":".*","write":".*","configure":".*"}
and an HTTP header Content-Type:application/json;charset=UTF-8
This all looks reasonable to me - but the response is
HTTP/1.1 415 Unsupported Media Type
This code is years old, and I suspect it is my RabbitMQ installation that is too new for it, but I'd like to rather make the code future-proof than to install an RabbitMQ from 2015 ...
I have googled extensively on this issue but all I found was some bug about doubled headers in the rabbitmq client software that is not in use here. I traced it into apache httpclient classes and there is nothing on the sender side that smells.
Any suggestions what is wrong?
It turned out that the Apache HttpClient was adding a second content-type header to the message, caused the rejection on RabbitMQ Management plugin.
Yes, content type should not be applied
curl -s -i -u guest:guest -H "content-type: application/json" -H "content-type: application/json" -X POST --data '{"properties":{"delivery_mode":2},"routing_key":"program.*","payload":"{\"id\":\"123456\"}","payload_encoding":"string"}' 'http://127.0.0.1:15672/api/exchanges/%2F/my-exchange/publish'
return HTTP/1.1 415 Unsupported Media Type
Without content-type or just one :
curl -s -i -u guest:guest -H "content-type: application/json" -X POST --data '{"properties":{"delivery_mode":2},"routing_key":"program.*","payload":"{\"id\":\"123456\"}","payload_encoding":"string"}' 'http://127.0.0.1:15672/api/exchanges/%2F/my-exchange/publish'
return HTTP/1.1 200 OK

In uploadcare, I'm getting an empty 403 error when using the upload POST endpoint

I'm using a raw post since I'm using react native and I didn't see a react-native library.
I'm getting a 403 response when trying to upload using the raw upload form post- is there a setting that I need to set or is my public key not activated or something? I don't see a text response in the 403 response so not sure what the specific error is.
Here's my sample CURL from postman
curl -X POST -H "Content-Type: multipart/form-data; boundary=..."
-F "UPLOADCARE_PUB_KEY=foo"
-F "UPLOADCARE_STORE=1"
-F "file=#logo.jpg" "https://upload.uploadcare.com/base/"
Here are few things you should look at:
content-type is not needed here
reason for 4xx should be stated in response body or headers
make sure that you don't have typos in API key
make sure that automatic storing is enabled in the project or send "UPLOADCARE_STORE=auto"
make sure that your account is not blocked, has some quota left, file type is allowed, etc.
don't rely on Postman, check the command with cURL
This works:
curl -vv -X POST \
-F "UPLOADCARE_PUB_KEY=demopublickey" \
-F "UPLOADCARE_STORE=1" \
-F "file=#logo.png" "https://upload.uploadcare.com/
I see you are trying to use multipart upload, how big is logo.jpg? Are you able to upload the same file using the dashboard?

curl -h or curl --header not working

i'm trying to connect ti a web api service, box-api, and following the tutorial i have to type this command to fetch a folder in the user content:
curl https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0 -H "Authorization: Bearer ACCESS_TOKEN"
I tryied to connect from the command line to test the command but it keep complaining about the -H or the --header command saying that it doesn exist:
-bash: -H: command not found
-bash: --header: command not found
but when i type curl --help the command is in the manual:
-H, --header LINE Custom header to pass to server (H)
I'm confused, what should i do to connect to this site and get the JSON content? Thanks
Your url has & sign. and this is making end of command on there(and running at background). You can remove this error by using quotes around. Like this
curl "https://api.box.com/2.0/folders/FOLDER_ID/items?limit=2&offset=0" -H "Authorization: Bearer ACCESS_TOKEN"
Hope this helps.
There seem to be two problems:
The '&' in the middle of the URL passed to curl,
The order of the statements. The curl manual reports a different order for the statements. Example:
curl -H "Authorization: Bearer AUTH_KEY" "https://api.box.com/2.0/folders/0/items?limit=2&offset=0"
This should be the complete solution.