Swift:未设置请求授权标头

时间:2018-11-03 10:14:52

标签: ios swift alamofire sylius

当我将内容类型标头设置为application/json,将Authorization标头设置为精确值 {{ 1}}通过邮递员可以很好地响应预期的响应,但是当我尝试通过Bearer SampleToken设置请求授权标头时,它会给我一个响应

URLRequest

当我通过查尔斯监视请求时,我注意到{ error = "access_denied"; "error_description" = "OAuth2 authentication required"; } 标头被剥夺了。我尝试了多种方法来设置授权标头,但没有运气。

Authorization

原始邮递员请求:

API

2 个答案:

答案 0 :(得分:0)

尝试更改

request.setValue("Bearer SampleToken", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

    request.allHTTPHeaderFields = [
       "Authorization": "Bearer SampleToken",
       "Content-Type": "application/json"
    ]

答案 1 :(得分:0)

您的授权令牌应为<b-form-input id="nestedCategory" v-model="productCategory" :value="category.name readonly/> 的base64编码的字符串

user:password