我正在成功执行以下请求:
curl -X POST \
http://apitoconnect.com/v1/tracking \
-H 'authorization: Basic dm...........PQ==' \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-d '{
"CarrierName": "xxxxxx",
"OrderNumber": "111111",
"ReceiptNumber": "0000000",
"ReceiptSerie": "0",
"Code": "0000000000",
"DateToDelivery": "2017-10-03",
"CompanyDocumentNumber": "00000000",
"CustomerEmail": "xxxx@yyyy.com",
"CustomerDocumentNumber": "000000000",
"CustomerPostalCode": "0000000000",
"SendSms": "true",
"SendEmail": "true",
"CustomerPhone": "00000000000",
"CustomerName": "Bill Gates",
"SalesChannel": "00000000"
}'
它工作得很好!但是当我尝试使用WordPress进行此操作时,我总是得到错误500.
这是我正在使用的代码:
$args = array(
'headers' => array(
'Authorization' => 'Basic ' . $token,
'Content-Type' => 'application/json'
),
'body' => array(
'OrderNumber' => '111111',
'ReceiptNumber' => '0000000',
'ReceiptSerie' => '0',
'Code' => '0000000000',
'DateToDelivery' => '2017-10-03',
'CarrierName' => 'xxxxxx',
'CompanyDocumentNumber' => '00000000',
'CustomerEmail' => 'xxxx@yyyy.com',
'CustomerPhone' => '00000000000',
'CustomerName' => 'Bill Gates',
'CustomerDocumentNumber' => '000000000',
'CustomerPostalCode' => '0000000000',
'SendSms' => true,
'SendEmail' => true,
'SalesChannel' => '00000000',
)
);
$response = wp_remote_post( esc_url_raw( $url ), $args );
我尝试json_encode( )
参数数组,但它也不起作用......
我的代码出了什么问题?
答案 0 :(得分:0)
在WP rest API的内部和外部,至少在我的服务器配置上,您需要手动设置用户代理。
Replace All