无法从 mangopay post 卡响应中获取 json
Can not get json from mangopay post card response
我正在尝试 post 注册卡感谢 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(),
});
当我在 post 上 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'。
我试过 postman 没有问题。但是,我得到的不是 json,而是一个简单的文本 'data = ....'。如何通过代码检索此数据?
提前致谢。
我找到了解决方案。您只需要使用 response.text() 而不是 response.json()..
我正在尝试 post 注册卡感谢 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(),
});
当我在 post 上 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'。
我试过 postman 没有问题。但是,我得到的不是 json,而是一个简单的文本 'data = ....'。如何通过代码检索此数据?
提前致谢。
我找到了解决方案。您只需要使用 response.text() 而不是 response.json()..