Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to pass "Content-Length" value in header using Curl Command

Tags:

curl

How can I pass content-length eg. --header Content-Length:1000 in curl command. I used it like this in command but it did't work

curl -v -X POST -u "[email protected]:xxx123" \       --header "Content-Length: 1000" \      --header "Content-Type: multipart/mixed" \      --header "X-REQUEST-ID:7fc7d038-4306-4fc5-89c3-7ac8a12a30d0" \      -F "request={\"bumId\":\"d51f2978-5ce8-4c71-8503-b0ca438741dd\",\"fileType\":\"imageFile\"};type=application/json" \      -F "file=@D:/file.pdf" \      "http://localhost:9090/pro/v1/files" 

This command posts file to a web services developed in Jersey Java

like image 369
Simer Avatar asked Nov 03 '15 05:11

Simer


People also ask

How do you pass header values in curl command?

To pass multiple headers in a curl request you simply add additional -H or --header to your curl command. For standard HTTP header fields such as User-Agent, Cookie, Host, there is actually another way to setting them.

Does curl set content-length automatically?

By default curl sets appropriate Content-Length header for you when data is provided with -d parameter. In your case the server seems to wait for some data in the body. But for some reason you decided to pass the data in the url.

What is content-length in HTTP header?

The Content-Length entity-header field indicates the size of the entity-body, in decimal number of OCTETs, sent to the recipient or, in the case of the HEAD method, the size of the entity-body that would have been sent had the request been a GET.


2 Answers

You can use -d "" causes CURL to send a Content-Length: 0,

see Header 'Content-Length: 0' is missing when I do curl -X POST $URI

like image 75
fangxing Avatar answered Oct 03 '22 11:10

fangxing


Try this: curl -X POST http://localhost:9090/pro/v1/files -d "Content-Length: 0"

curl's -d flag allows you to add data to the body of the request. According to its docs:

-d, --data (HTTP) Sends the specified data in a POST request to the HTTP server, in the same way that a browser does when a user has filled in an HTML form and presses the submit button. This will cause curl to pass the data to the server using the content-type application/x-www-form-urlencoded.

like image 36
MaxLis Avatar answered Oct 03 '22 11:10

MaxLis