46 lines
1.4 KiB
Markdown
46 lines
1.4 KiB
Markdown
|
|
## Multiple header values
|
||
|
|
when you have more than one header value, ie you want to pass the authentication token **and** you want to pass json values
|
||
|
|
|
||
|
|
simply state each header value separately while preceeding it with the -H/--header prefix
|
||
|
|
|
||
|
|
e.g.
|
||
|
|
|
||
|
|
`-H "Authentication: Bearer 2342343" \`
|
||
|
|
`-H "Content-Type: application/json" `
|
||
|
|
|
||
|
|
note the forward slash \ is used to separate between lines for readability
|
||
|
|
|
||
|
|
## Passing the Authentication token
|
||
|
|
|
||
|
|
get an authentication token from the server
|
||
|
|
then pass it in through the header
|
||
|
|
|
||
|
|
`--header "Authorization: Bearer <token>`
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
## Passing Json Values Through Curl
|
||
|
|
|
||
|
|
##### step 1 - set the header
|
||
|
|
`--header "Content-Type: application/json"`
|
||
|
|
|
||
|
|
##### step 2 - encode the values
|
||
|
|
`-d "{\"name\":\"$2\", \"code\":\"$3\"}"`
|
||
|
|
|
||
|
|
the bracketed area must be enclose with double quotes (single could work, but we need to change the parameters into strings, and bash does not seem to do that with singles)
|
||
|
|
|
||
|
|
the parameter names and values must also be enclosed in **backslashed** double quotes
|
||
|
|
|
||
|
|
`\"`
|
||
|
|
|
||
|
|
this means the entire string has to be enclosed in normal doubles instead of singles to interpolate the values
|
||
|
|
|
||
|
|
|
||
|
|
## various
|
||
|
|
|
||
|
|
[how can i set the request header for curl](https://stackoverflow.com/questions/4212503/how-can-i-set-the-request-header-for-curl/45313572)
|
||
|
|
|
||
|
|
[curl snippets](https://gist.github.com/subfuzion/08c5d85437d5d4f00e58)
|
||
|
|
|
||
|
|
###### interpolate
|
||
|
|
*insert (something of a different nature) into something else.*
|