gpt4 book ai didi

curl - axios:在 axios 中传递 curl 的 -d

转载 作者:太空宇宙 更新时间:2023-11-03 15:46:58 31 4
gpt4 key购买 nike

我在将 curl -d 数据转换为 axios 时遇到问题,我可以毫无问题地完成它,只需 curl ......这就是我需要传递的数据

curl https://api-3t.sandbox.paypal.com/nvp
-s
-d USER=Caller_ID
-d PWD=Caller_Pswd
-d SIGNATURE=Caller_Sig
-d METHOD=SetExpressCheckout
-d RETURNURL=https://example.com/success.html
-d CANCELURL=https://example.com/canceled.html
-d VERSION=93 # API version
-d PAYMENTREQUEST_0_CURRENCYCODE=USD
-d PAYMENTREQUEST_0_AMT=250
-d PAYMENTREQUEST_0_ITEMAMT=225
-d PAYMENTREQUEST_0_TAXAMT=25
-d PAYMENTREQUEST_0_PAYMENTACTION=Sale
-d PAYMENTREQUEST_0_DESC=Sandwich Combo
-d PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID=Receiver_1
-d PAYMENTREQUEST_0_PAYMENTREQUESTID=CART1
-d L_PAYMENTREQUEST_0_NAME0=Super Sub
-d L_PAYMENTREQUEST_0_NUMBER0=SS-101 \
-d L_PAYMENTREQUEST_0_QTY0=1 \
-d L_PAYMENTREQUEST_0_AMT0=125 \
-d L_PAYMENTREQUEST_0_TAXAMT0=15
-d L_PAYMENTREQUEST_0_NAME1=Classic Wineinformation
-d L_PAYMENTREQUEST_0_QTY1=1
-d L_PAYMENTREQUEST_0_AMT1=100
-d L_PAYMENTREQUEST_0_TAXAMT1=10
-d PAYMENTREQUEST_1_CURRENCYCODE=USD
-d PAYMENTREQUEST_1_AMT=75
-d PAYMENTREQUEST_1_ITEMAMT=65
-d PAYMENTREQUEST_1_TAXAMT=10
-d PAYMENTREQUEST_1_PAYMENTACTION=Sale
-d PAYMENTREQUEST_1_DESC=Mocktail Large
-d PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID=Receiver_2
-d PAYMENTREQUEST_1_PAYMENTREQUESTID=CART2
-d L_PAYMENTREQUEST_1_NAME0=Orange crush
-d L_PAYMENTREQUEST_1_NUMBER0=MC-77
-d L_PAYMENTREQUEST_1_QTY0=1
-d L_PAYMENTREQUEST_1_AMT0=65
-d L_PAYMENTREQUEST_1_TAXAMT0=10

这是一个 Paypal API:https://developer.paypal.com/docs/classic/express-checkout/ht_ec-parallelPayments/?mark=parallel#create-a-parallel-payment

使用这种类型的数据,我的发帖请求应该是什么样子?

最佳答案

检查 Using application/x-www-form-urlencoded format来自 Axios 文档

如果您在浏览器中使用它:

const params = new URLSearchParams();
params.append('USER', 'Caller_ID');
params.append('PWD', 'Caller_Pswd');
params.append('SIGNATURE', 'Caller_Sig');
params.append('METHOD', 'SetExpressCheckout');
params.append('RETURNURL', 'https://example.com/success.html');
params.append('CANCELURL', 'https://example.com/canceled.html');
params.append('VERSION', 93);
params.append('PAYMENTREQUEST_0_CURRENCYCODE', 'USD');
params.append('PAYMENTREQUEST_0_AMT', 250);
params.append('PAYMENTREQUEST_0_ITEMAMT', 225);
params.append('PAYMENTREQUEST_0_TAXAMT', 25);
params.append('PAYMENTREQUEST_0_PAYMENTACTION', 'Sale');
params.append('PAYMENTREQUEST_0_DESC', 'Sandwich Combo');
params.append('PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID', 'Receiver_1');
params.append('PAYMENTREQUEST_0_PAYMENTREQUESTID', 'CART1');
params.append('L_PAYMENTREQUEST_0_NAME0', 'Super Sub');
params.append('L_PAYMENTREQUEST_0_NUMBER0', 'SS-101');
params.append('L_PAYMENTREQUEST_0_QTY0', 1);
params.append('L_PAYMENTREQUEST_0_AMT0', 125);
params.append('L_PAYMENTREQUEST_0_TAXAMT0', 15);
params.append('L_PAYMENTREQUEST_0_NAME1', 'Classic Wineinformation');
params.append('L_PAYMENTREQUEST_0_QTY1', 1);
params.append('L_PAYMENTREQUEST_0_AMT1', 100);
params.append('L_PAYMENTREQUEST_0_TAXAMT1', 10);
params.append('PAYMENTREQUEST_1_CURRENCYCODE', 'USD');
params.append('PAYMENTREQUEST_1_AMT', 75);
params.append('PAYMENTREQUEST_1_ITEMAMT', 65);
params.append('PAYMENTREQUEST_1_TAXAMT', 10);
params.append('PAYMENTREQUEST_1_PAYMENTACTION', 'Sale');
params.append('PAYMENTREQUEST_1_DESC', 'Mocktail Large');
params.append('PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID', 'Receiver_2');
params.append('PAYMENTREQUEST_1_PAYMENTREQUESTID', 'CART2');
params.append('L_PAYMENTREQUEST_1_NAME0', 'Orange crush');
params.append('L_PAYMENTREQUEST_1_NUMBER0', 'MC-77');
params.append('L_PAYMENTREQUEST_1_QTY0', 1);
params.append('L_PAYMENTREQUEST_1_AMT0', 65);
params.append('L_PAYMENTREQUEST_1_TAXAMT0', 1);

axios.post('https://api-3t.sandbox.paypal.com/nvp', params);
.then(function(response) {
//handle success
console.log(response);
})
.catch(function(response) {
//handle error
console.log(response);
});

来自 :

const querystring = require('querystring');
axios.post('https://api-3t.sandbox.paypal.com/nvp', querystring.stringify({
USER: "Caller_ID",
PWD: "Caller_Pswd",
SIGNATURE: "Caller_Sig",
METHOD: "SetExpressCheckout",
RETURNURL: "https: //example.com/success.html",
CANCELURL: "https: //example.com/canceled.html ",
VERSION: 93,
PAYMENTREQUEST_0_CURRENCYCODE: "USD",
PAYMENTREQUEST_0_AMT: 250,
PAYMENTREQUEST_0_ITEMAMT: 225,
PAYMENTREQUEST_0_TAXAMT: 25,
PAYMENTREQUEST_0_PAYMENTACTION: "Sale",
PAYMENTREQUEST_0_DESC: "Sandwich Combo",
PAYMENTREQUEST_0_SELLERPAYPALACCOUNTID: "Receiver_1",
PAYMENTREQUEST_0_PAYMENTREQUESTID: "CART1",
L_PAYMENTREQUEST_0_NAME0: "Super Sub",
L_PAYMENTREQUEST_0_NUMBER0: "SS-101",
L_PAYMENTREQUEST_0_QTY0: 1,
L_PAYMENTREQUEST_0_AMT0: 125,
L_PAYMENTREQUEST_0_TAXAMT0: 15,
L_PAYMENTREQUEST_0_NAME1: "Classic Wineinformation",
L_PAYMENTREQUEST_0_QTY1: 1,
L_PAYMENTREQUEST_0_AMT1: 100,
L_PAYMENTREQUEST_0_TAXAMT1: 10,
PAYMENTREQUEST_1_CURRENCYCODE: "USD",
PAYMENTREQUEST_1_AMT: 75,
PAYMENTREQUEST_1_ITEMAMT: 65,
PAYMENTREQUEST_1_TAXAMT: 10,
PAYMENTREQUEST_1_PAYMENTACTION: "Sale",
PAYMENTREQUEST_1_DESC: "Mocktail Large",
PAYMENTREQUEST_1_SELLERPAYPALACCOUNTID: "Receiver_2",
PAYMENTREQUEST_1_PAYMENTREQUESTID: "CART2",
L_PAYMENTREQUEST_1_NAME0: "Orange crush",
L_PAYMENTREQUEST_1_NUMBER0: "MC-77",
L_PAYMENTREQUEST_1_QTY0: 1,
L_PAYMENTREQUEST_1_AMT0: 65,
L_PAYMENTREQUEST_1_TAXAMT0: 1,
}));

关于curl - axios:在 axios 中传递 curl 的 -d,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53134429/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com