Paypal UNSUPPORTED_MEDIA_TYPE

烈酒焚心 提交于 2019-12-20 02:12:24

问题


I am trying to get an access token from paypal's authorization api. When I make post request to the api I get UNSUPPORTED_MEDIA_TYPE i.e. 415 response.

Below is the snippet that I used.

const auth = await fetch(PAYPAL_OAUTH_API, {
    method: 'post',
    headers: {
        'Content-Type': 'application/json',
        'Authorization': `Basic ${ basicAuth }`
    },
    body: JSON.stringify({"grant_type": "client_credentials"})
});

回答1:


I have fixed my issue by setting Content-Type to application/x-www-form-urlencoded.

My guess is paypal accepts only application/x-www-form-urlencoded for authorization api.




回答2:


I ran into same issue, and the solution is following (using Postman):

  1. Select POST
  2. Add Token into Authorization, type is Bearer-Token
  3. Select Content-Type: application/json in headers
  4. Use RAW as body, and in TEXT dropdown, select JSON (application/JSON)
  5. Copy body as raw object and change info accordingly.

Step 4 and 5 are what solved the error, you must send raw json object.



来源:https://stackoverflow.com/questions/54683642/paypal-unsupported-media-type

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!