问题
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):
- Select POST
- Add
Token
intoAuthorization
, type is Bearer-Token - Select
Content-Type: application/json
in headers - Use
RAW
as body, and inTEXT
dropdown, select JSON (application/JSON
) - 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