How to send a header using a HTTP request through a curl call?

后端 未结 10 1387
梦如初夏
梦如初夏 2020-11-22 16:45

I wish to send a header to my Apache server on a Linux box. How can I achieve this via a curl call?

10条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 17:16

    In anaconda envirement through windows the commands should be: GET, for ex:

    curl.exe http://127.0.0.1:5000/books 
    

    Post or Patch the data for ex:

    curl.exe http://127.0.0.1:5000/books/8 -X PATCH -H "Content-Type: application/json" -d '{\"rating\":\"2\"}' 
    

    PS: Add backslash for json data to avoid this type of error => Failed to decode JSON object: Expecting value: line 1 column 1 (char 0)

    and use curl.exe instead of curl only to avoid this problem:

    Invoke-WebRequest : Cannot bind parameter 'Headers'. Cannot convert the "Content-Type: application/json" value of type
    "System.String" to type "System.Collections.IDictionary".
    At line:1 char:48
    + ... 0.1:5000/books/8 -X PATCH -H "Content-Type: application/json" -d '{\" ...
    +                                  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidArgument: (:) [Invoke-WebRequest], ParameterBindingException
        + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
    

提交回复
热议问题