多亏了Mangopay API (这里是明信片路径信息:https://docs.mangopay.com/endpoints/v2.01/cards#e1042_post-card-info),我正在尝试邮寄一张注册卡。
fetch(cardRegistration.CardRegistrationURL, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
},
body: new URLSearchParams({
accessKeyRef: accessKeyRef,
data: data,
cardNumber: cardNumber,
cardExpirationDate: expiration,
cardCvx: cvx,
}).toString(),
});当我在这个url (https://homologation-webpayment.payline.com/webpayment/getToken)上发帖时,我的状态是200,但是我不能通过response.json()获取数据,我不明白为什么。
这是我得到的回应:
{
"type": "default",
"status": 200,
"ok": true,
"statusText": "",
"headers": {
"map": {
"server": "Apache",
"connection": "Keep-Alive",
"access-control-allow-origin": "*",
"keep-alive": "timeout=15, max=100",
"date": "Wed, 22 Sep 2021 15:21:11 GMT",
"vary": "Accept-Encoding,User-Agent",
"content-length": "155",
"content-type": "text/plain"
}
},
"url": "https://homologation-webpayment.payline.com/webpayment/getToken",
"bodyUsed": false,
"_bodyInit": {
"_data": {
"size": 155,
"offset": 0,
"blobId": "415DAFF0-5B8F-429E-91F2-4FC94765A2C2",
"type": "text/plain",
"name": "getToken.txt",
"__collector": {}
}
},
"_bodyBlob": {
"_data": {
"size": 155,
"offset": 0,
"blobId": "415DAFF0-5B8F-429E-91F2-4FC94765A2C2",
"type": "text/plain",
"name": "getToken.txt",
"__collector": {}
}
}
}但是在调用JSON方法之后,我不能继续。
let card = await postCardResponse.json()
console.log('hello')控制台永远不会显示“hello”。
我试过了邮递员,我没有问题。然而,我得到的不是一个json,而是一个简单的文本'data = ....‘。如何通过代码检索这些数据?
提前谢谢。
发布于 2021-09-22 15:47:48
我找到了解决方案。您只需使用response.text()而不是response.json()。
https://stackoverflow.com/questions/69287282
复制相似问题