如何传递两个授权标头以卷曲POST请求

问题描述 投票:0回答:2

我正在访问Rest API。我必须做POST。 Web服务托管在基本身份验证之后。要访问给定的端点,我还必须发送一个授权标头。

情况1:curl GEThttp://username:[email protected]/endpoint1=>有效

情况2:curl GEThttp://@example.com/endpoint1-H“授权:基本base64_encode(username:password)” =>作品

情况3:curl POSThttp://@example.com/endpoint2-H“授权:基本base64_encode(用户名:密码),基本another_auth_token” =>不起作用

案例4:curl POSThttp://username:[email protected]/endpoint2-H“授权:基本的another_auth_token” =>不起作用

也尝试使用php curl curl_setopt($ ch,CURLOPT_USERPWD,'username:password'),它不起作用。

[已尝试添加标题,内容类型:application / json和application / x-www-form-urlencoded,但无效。

我需要带有两个授权标头的curl POST才能工作。

任何指针可能会丢失什么?

rest authentication curl http-headers authorization
2个回答
0
投票
    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'

对于CURL中的body参数,您应该在最后一个Header参数之后使用-d'{您的json中的body}。(-H)


0
投票

只需两次通过“ -H授权”:

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

我得到:

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

但是请记住,服务器(以及下游服务器)必须能够处理多个授权标头。

© www.soinside.com 2019 - 2024. All rights reserved.