[curl] How to use curl to get a GET request exactly same as using Chrome?

I have a web api http://something.com/api and I want to use GET to get the response body.

This is my command:

curl "http://something.com/api"

Of course, it fails and gives an error message.

When I use Chrome and input the above url, everythings correct. However I do the same things with Firefox, the url gives me the same error message. I try to repeat the action with Chrome extension DHC, the request gives correct response again. After some searching, I believe that the curl option --user-agent makes a difference. What is the correct way to set the user agent to Chrome? Or this is not the point, the problem comes from other fields? Thank you very much.

This question is related to curl user-agent

The answer is


Check the HTTP headers that chrome is sending with the request (Using browser extension or proxy) then try sending the same headers with CURL - Possibly one at a time till you figure out which header(s) makes the request work.

curl -A [user-agent] -H [headers] "http://something.com/api"


Open Chrome Developer Tools, go to Network tab, make your request (you may need to check "Preserve Log" if the page refreshes). Find the request on the left, right-click, "Copy as cURL".