0
votes

I'm accessing a rest api. I have to do POST. The webservice is hosted behind the basic authentication. To access the given endpoint I have to also send an authorization header.

case 1: curl GET http://username:[email protected]/endpoint1 => works

case 2: curl GET http://@example.com/endpoint1 -H "Authorization: Basic base64_encode(username:password)" => works

case 3: curl POST http://@example.com/endpoint2 -H "Authorization: Basic base64_encode(username:password), Basic another_auth_token" => does not work

case 4: curl POST http://username:[email protected]/endpoint2 -H "Authorization: Basic another_auth_token" => does not work

Also tried using php curl curl_setopt($ch, CURLOPT_USERPWD, 'username:password') and it didn't work.

Tried adding headers, Content-Type: application/json and application/x-www-form-urlencoded and it didn't work.

I need curl POST with the two authorization headers to work.

Any pointers what could be missing?

2
what is error you are getting? are you sure you have to post two headers? or pass the second set of details in the body of the POST?bitsNbytes

2 Answers

0
votes
    curl -X POST
'https://api.amazon / shopify or "your URL"/'
-H 'Authorization: Bearer {token}' // or/AND your USER KEY and PASS in Base 64
-H 'Accept: application/json'
-H 'Content-Type: application/json'

for body parameter in CURL You should use -d'{your body in json}after the last Header param.(-H)

0
votes

Just pass '-H Authorization' twice:

curl -X POST http://example.com/endpoint2 \
    -H "Authorization: Basic base64_encode_username_colo_password" \
    -H "Authorization: Basic another_auth_token"

I get:

POST / HTTP/1.1
Host: localhost:10101
User-Agent: curl/7.47.0
Accept: */*
Authorization: Basic base64_encode_username_colo_password
Authorization: Basic another_auth_token

Keep in mind, though, that the server (and downstream servers as well) has to be able to deal with multiple authorization headers.