Search code examples
curl

Sec-Ch-Ua header not working on cmd with curl


curl: (3) URL rejected: Malformed input to a URL function

curl: (3) URL rejected: Bad hostname

curl: (3) URL rejected: Bad hostname

I need use sec-ch-ua header in my request but getting error

-H ' "Not_A Brand";v="8", "Chromium";v="120" ' -H "sec-ch-ua: ^^"Not_A Brand^^";v=^^"8^^", ^^"Chromium^^";v=^^"120^^"" ^

Not working. How to use sec-ch-ua header in cmd "Not_A Brand";v="8", "Chromium";v="120"


Solution

  • Supposing you want to use Windows CMD (commandline) to start curl, try to escape " as \" (see How to send double quote in -d parameter for curl.exe?)

    And then, the name of the header is Sec-CH-UA, you have to take care for uppercase/lowercase letters! See the MDN page on Sec-CH-UA

    So in total, this should work for you:

    curl ... -H "Sec-CH-UA: \"Not_A Brand\";v=\"8\", \"Chromium\";v=\"120\""
    

    Your attempt contained a header without a name - also you probably missed out the part that I just scribbled as ... where you have to give the URL and the HTTP method like GET, PUT or similar.

    See the manual page for curl to learn about the general usage of curl if necessary or use that as a reference manual - curl has so many options it probably is very hard to remember them all.

    Also I'm not sure if that header will be of much use with curl instead of a desktop browser, but you might have a valid reason to send it, maybe one of the Use cases for User-Agent Client Hints on the MDN.