【问题标题】:browser sent an invalid request to server浏览器向服务器发送了无效请求
【发布时间】:2019-03-30 20:25:56
【问题描述】:

我需要调用 webservice api url & fetch result....

JSON 负载由 API 团队提供:

{
"request_id": "R09",
"client_name": "CLIENT",
"services": [
{
"service_code": "REGULAR",
"service_details": [
{
"service_leg": "FORWARD",
"service_data": {
"vendor_name":"Ekart",
"amount_to_collect": 1000,
"dispatch_date": "",
"customer_promise_date": "",
"delivery_type": "SMALL",
"source": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
},
"destination": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
},
"return_location": {
"address": {
"first_name": "AVThamizhmahan",
"address_line1": "3/1675 ES Garden Vazhudaretty Post Villupuram",
"address_line2": "Tamil Nadu",
"pincode": "400066",
"city": "Villupuram",
"state": "Tamil Nadu",
"primary_contact_number": "88888888"
}
}
},
"shipment": {
"client_reference_id": "ABCD",
"tracking_id": "CLTC0000000001",
"shipment_value": 2000,
"shipment_dimensions": {
"length": {
"value": 1
},
"breadth": {
"value": 1
},
"height": {
"value": 1
},
"weight": {
"value": 1
}
},
"return_label_desc_1": "",
"return_label_desc_2": "",
"shipment_items": [
{
"product_id": "134883075",
"item_content":{},
"category": "Apparel",
"product_title": "Mast&HarbourBlackHandbag: Handbags",
"quantity": 1,
"cost": {
"total_sale_value": 500,
"total_tax_value": 100 ,
“tax_breakup”:{
“cgst”:0.0,
“sgst”:0.0,
“igst”:0.0
}
},
"seller_details": {
"seller_reg_name": "Seller Registered Legal Name",
"vat_id": "",
"cst_id": "",
“tin_id”:””,
“gstin_id”:””
},
“hsn” :””,
“ern”:””,
“discount”:0.0,
"legal_entity": "",
"billable_entity": "",
"cod_remittance_entity": "",
"item_attributes": [
{
"name": "order_id",
"value": "ABCD"
},
{
"name": "invoice_id",
"value": "INV1234"
},
{
"name": "item_dimensions",
"value": "l:b:h:w"
},
{
"name": "brand_name",
"value": "Peter England"
}
],
"handling_attributes": [
{
"name": "isFragile",
"value": "false"
},
{
"name": "isDangerous",
"value": "false"
}
]
}
]
}
}
]
}
]
}

我将 JSon 称为数组并传递 url:

<?php

$url = "https://staging.logistics.com/v2/shipments/create";

$data = array
( 
"request_id"=> "R09",
"client_name"=> "DOC",
"services"=> [
array (
"service_code"=> "REGULAR",
"service_details"=> [
array (
"service_leg"=> "FORWARD",
"service_data"=> array (
"vendor_name"=>"Ekart",
"amount_to_collect"=> 1000,
"dispatch_date"=> "",
"customer_promise_date"=> "",
"delivery_type"=> "SMALL",
"source"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"destination"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"return_location"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "400066",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
)
),
"shipment"=> array (
"client_reference_id"=> "ABCD",
"tracking_id"=> "DOCC0000000001",
"shipment_value"=> 2000,
"shipment_dimensions"=> array (
"length"=> array (
"value"=> 1
),
"breadth"=> array (
"value"=> 1
),
"height"=> array (
"value"=> 1
),
"weight"=> array (
"value"=> 1
)
),
"return_label_desc_1"=> "",
"return_label_desc_2"=> "",
"shipment_items"=> [
array (
"product_id"=> "134883075",
"item_content"=>array (),
"category"=> "Apparel",
"product_title"=> "Mast&HarbourBlackHandbag=> Handbags",
"quantity"=> 1,
"cost"=> array (
"total_sale_value"=> 500,
"total_tax_value"=> 100 ,
"tax_breakup"=>array (
"cgst"=>0.0,
"sgst"=>0.0,
"igst"=>0.0
)
),
"seller_details"=> array (
"seller_reg_name"=> "Seller Registered Legal Name",
"vat_id"=> "",
"cst_id"=> "",
"tin_id"=>"",
"gstin_id"=>""
),
"hsn" =>"",
"ern"=>"",
"discount"=>0.0,
"legal_entity"=> "",
"billable_entity"=> "",
"cod_remittance_entity"=> "",
"item_attributes"=> [
array (
"name"=> "order_id",
"value"=> "ABCD"
),
array (
"name"=> "invoice_id",
"value"=> "INV1234"
),
array (
"name"=> "item_dimensions",
"value"=> "l=>b=>h=>w"
),
array (
"name"=> "brand_name",
"value"=> "Peter England"
)
],
"handling_attributes"=> [
array (
"name"=> "isFragile",
"value"=> "false"
),
array (
"name"=> "isDangerous",
"value"=> "false"
)
]
)
]
)
)
]
)
]
);
echo $data=json_encode($data);
$data_string = json_encode(array(
    "Payload" => $data
));

$ch = curl_init($url);

curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type : application/json"
));

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     "Authorization : Basic ZGFpbHlvcmRlcnM6ZHVtbf4fsww="
));

curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);

curl_setopt($ch, CURLOPT_POST, 1); 
curl_close($ch);

echo "$result";

?>

回应

400 Bad request
Your browser sent an invalid request.

我发送的格式是否正确?

这里是 APi 文档:https://drive.google.com/open?id=13AstBwus-uErvElg2-FN0knIy1m9lMHa

如果您需要任何其他信息,请告诉我......

我正在使用 ekart api.....

在此先感谢....

更新

以下是 POSTMAN 结果:

更新 2:

错误

{"response":[{"status":"REQUEST_REJECTED","message":["X_Merchant_Code is null"]}],"request_id":"2aa4cf98-0b59-4e2d-ba10-79c39663d6b6"}

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
mysqli_report(MYSQLI_REPORT_ALL & ~MYSQLI_REPORT_INDEX);

$url = "https://staging.ekartlogistics.com/v2/shipments/create";

$data1 = array
( 
"request_id"=> "835",
"client_name"=> "DOC",
"services"=> [
array (
"service_code"=> "REGULAR",
"service_details"=> [
array (
"service_leg"=> "FORWARD",
"service_data"=> array (
"vendor_name"=>"Ekart",
"amount_to_collect"=> 1000,
"dispatch_date"=> "",
"customer_promise_date"=> "",
"delivery_type"=> "SMALL",
"source"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "560034",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"destination"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "110037",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
),
"return_location"=> array (
"address"=> array (
"first_name"=> "AVThamizhmahan",
"address_line1"=> "31675 ES Garden Vazhudaretty Post Villupuram",
"address_line2"=> "Tamil Nadu",
"pincode"=> "110037",
"city"=> "Villupuram",
"state"=> "Tamil Nadu",
"primary_contact_number"=> "88888888"
)
)
),
"shipment"=> array (
"client_reference_id"=> "ABCD",
"tracking_id"=> "DOCC0000000001",
"shipment_value"=> 2000,
"shipment_dimensions"=> array (
"length"=> array (
"value"=> 1
),
"breadth"=> array (
"value"=> 1
),
"height"=> array (
"value"=> 1
),
"weight"=> array (
"value"=> 1
)
),
"return_label_desc_1"=> "",
"return_label_desc_2"=> "",
"shipment_items"=> [
array (
"product_id"=> "134883075",
"item_content"=>array (),
"category"=> "Apparel",
"product_title"=> "Mast&HarbourBlackHandbag=> Handbags",
"quantity"=> 1,
"cost"=> array (
"total_sale_value"=> 500,
"total_tax_value"=> 100 ,
"tax_breakup"=>array (
"cgst"=>0.0,
"sgst"=>0.0,
"igst"=>0.0
)
),
"seller_details"=> array (
"seller_reg_name"=> "Seller Registered Legal Name",
"vat_id"=> "",
"cst_id"=> "",
"tin_id"=>"",
"gstin_id"=>""
),
"hsn" =>"",
"ern"=>"",
"discount"=>0.0,
"legal_entity"=> "",
"billable_entity"=> "",
"cod_remittance_entity"=> "",
"item_attributes"=> [
array (
"name"=> "order_id",
"value"=> "ABCD"
),
array (
"name"=> "invoice_id",
"value"=> "INV1234"
),
array (
"name"=> "item_dimensions",
"value"=> "l=>b=>h=>w"
),
array (
"name"=> "brand_name",
"value"=> "Peter England"
)
],
"handling_attributes"=> [
array (
"name"=> "isFragile",
"value"=> "false"
),
array (
"name"=> "isDangerous",
"value"=> "false"
)
]
)
]
)
)
]
)
]
);
echo $data=json_encode(array("payload"=>$data1));
echo "<br/><br/>";//die;
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($curl, CURLOPT_HTTPHEADER, Array("Content-Type: application/json", "X_Merchant_Code: DOC"));


curl_setopt($curl, CURLOPT_USERPWD, "dailyorders:dummyKey"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //IMP if the url has https and you don't want to verify source certificate

$curl_response = curl_exec($curl);

curl_close($curl);

print_r($curl_response);die;


?>

【问题讨论】:

  • 你是如何发送 json 的?使用 ajax 请求将其发布在 POSTMAN 中,还有别的吗?您如何阅读 PHP 脚本中发布的 JSON?
  • @chiliNUT 感谢您的回复,我正在为此使用 curl ......
  • @chiliNUT 如果我以错误的方式呼叫,请指导我如何以正确的方式呼叫以获得正确的响应.....
  • 你的 CURL 上是否缺少 PUT 方法
  • 再次尝试检查您的参数。您将 json 数据嵌套到文档不需要的 PayLoad 中。只尝试 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);

标签: php


【解决方案1】:

您的 JSON 数组中似乎有错误:

“vendor_name”:”Ekart”,

引用不正确:

"vendor_name":"Ekart",

应该会更好。

还有一些类似的错误。 您应该使用a JSON editor 来检查您的 JSON 数组。

【讨论】:

  • 对不起,这是错字,不是问题,我现在更新了问题......
  • 好的,抱歉。我也编辑了^^如果我找到一些解决方案,我会编辑这个答案。
  • 我需要在php中传入json format而不是array吗?
  • 感谢您的建议,请告诉我在我的情况下如何通过http请求使用json,我需要更新哪些代码?
【解决方案2】:

假设你的参数是正确的。

尝试:

echo $data=json_encode($data);
//$data_string = json_encode(array(
//    "Payload" => $data
//));
   $username = "";
   $password = "";
   $ch = curl_init();
   curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);     
    curl_setopt($ch, CURLOPT_HEADER, true); 
    //curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    //    "Authorization : yourtoken",
    //));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
         "Content-Type : application/json"
    ));
    curl_setopt($process, CURLOPT_USERPWD, $username . ":" . $password);//since you are using basic auth  
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

    $return = curl_exec($ch);

    curl_close ($ch);

【讨论】:

【解决方案3】:

设置标题时,标题名称和分隔冒号之间有一个空格。这导致 Curl 使用两个标头,一个 Content-Type : application/json 标头和一个 Content-Type: application/x-www-form-urlencoded 标头,这是发布数据时的默认设置。服务器可以使用第二个标头将内容类型识别为“x-www-form-urlencoded”,但是第一个标头会导致 400 响应,因为标头和冒号之间不应有空格。来自rfc7230,第 3.2.4 节:

标题字段名和冒号之间不允许有空格。在 过去,处理此类空白的差异导致 请求路由和响应处理中的安全漏洞。一种 服务器必须拒绝任何接收到的请求消息,其中包含 标头字段名称和冒号之间的空格以及响应代码 400(错误请求)。

您的代码应该使用下面的标头返回成功的响应。

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
     "Authorization: Basic ZGFpbHlvcmRlcnM6ZHVtbf4fsww=", 
     "Content-Type: application/json"
));

在调试此类问题时,最好启用详细模式,该模式会打印有关连接的有用信息。

curl_setopt($ch, CURLOPT_VERBOSE, true);

在您的 Postman 请求中,您提交了 HTTP_X_MERCHANT_CODE 标头;您应该将其包含在您的 Curl 请求中。

$headers = array(
    "Authorization: Basic ZGFpbHlvcmRlcnM6ZHVtbXlLZXk=",
    "Content-Type: application/json", 
    "HTTP_X_MERCHANT_CODE: DOC",
);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);

这将修复“X_Merchant_Code is null”错误,但服务器会返回一条新的错误消息:“Expected BEGIN_OBJECT but was BEGIN_ARRAY”,指向:...shipment.shipment_items[0].item_content,因为 json 数据没有所需的格式。 item_content 键是一个空数组,它被编码为 [],但服务器需要一个 json 对象 ({})。如果我们使用空对象,我们可以解决这个问题。

$data['services'][0]['service_details'][0]['shipment']['shipment_items'][0]['item_content'] = (object)null;

完整代码:

<?php

$data = [
    "request_id" => "835",
    "client_name" => "DOC",
    "services" => [
        [
            "service_code" => "REGULAR",
            "service_details" => [
                [
                    "service_leg" => "FORWARD",
                    "service_data" => [
                        "vendor_name" => "Ekart",
                        "amount_to_collect" => 1000,
                        "dispatch_date" => "",
                        "customer_promise_date" => "",
                        "delivery_type" => "SMALL",
                        "source" => [
                            "address" => [
                                "first_name" => "AVThamizhmahan",
                                "address_line1" => "3/1675 ES Garden Vazhudaretty Post Villupuram",
                                "address_line2" => "Tamil Nadu",
                                "pincode" => "400066",
                                "city" => "Villupuram",
                                "state" => "Tamil Nadu",
                                "primary_contact_number" => "88888888"
                            ]
                        ],
                        "destination" => [
                            "address" => [
                                "first_name" => "AVThamizhmahan",
                                "address_line1" => "3/1675 ES Garden Vazhudaretty Post Villupuram",
                                "address_line2" => "Tamil Nadu",
                                "pincode" => "400066",
                                "city" => "Villupuram",
                                "state" => "Tamil Nadu",
                                "primary_contact_number" => "88888888"
                            ]
                        ],
                        "return_location" => [
                            "address" => [
                                "first_name" => "AVThamizhmahan",
                                "address_line1" => "3/1675 ES Garden Vazhudaretty Post Villupuram",
                                "address_line2" => "Tamil Nadu",
                                "pincode" => "400066",
                                "city" => "Villupuram",
                                "state" => "Tamil Nadu",
                                "primary_contact_number" => "88888888"
                            ]
                        ]
                    ],
                    "shipment" => [
                        "client_reference_id" => "ABCD",
                        "tracking_id" => "DOCC0000000001",
                        "shipment_value" => 2000,
                        "shipment_dimensions" => [
                            "length" => [
                                "value" => 1
                            ],
                            "breadth" => [
                                "value" => 1
                            ],
                            "height" => [
                                "value" => 1
                            ],
                            "weight" => [
                                "value" => 1
                            ]
                        ],
                        "return_label_desc_1" => "",
                        "return_label_desc_2" => "",
                        "shipment_items" => [
                            [
                                "product_id" => "134883075",
                                "item_content" => (object)null,
                                "category" => "Apparel",
                                "product_title" => "Mast&HarbourBlackHandbag => Handbags",
                                "quantity" => 1,
                                "cost" => [
                                    "total_sale_value" => 500,
                                    "total_tax_value" => 100
                                ],
                                "seller_details" => [
                                    "seller_reg_name" => "Seller Registered Legal Name",
                                    "vat_id" => "",
                                    "cst_id" => ""
                                ],
                                "legal_entity" => "",
                                "billable_entity" => "",
                                "cod_remittance_entity" => "",
                                "item_attributes" => [
                                    [
                                        "name" => "order_id",
                                        "value" => "ABCD"
                                    ],
                                    [
                                        "name" => "invoice_id",
                                        "value" => "INV1234"
                                    ],
                                    [
                                        "name" => "item_dimensions",
                                        "value" => "l:b:h:w"
                                    ],
                                    [
                                        "name" => "brand_name",
                                        "value" => "Peter England"
                                    ]
                                ],
                                "handling_attributes" => [
                                    [
                                        "name" => "isFragile",
                                        "value" => "false"
                                    ],
                                    [
                                        "name" => "isDangerous",
                                        "value" => "false"
                                    ]
                                ]
                            ]
                        ]
                    ]
                ]
            ]
        ]
    ]
];

$url = "https://staging.ekartlogistics.com/v2/shipments/create";
$data = json_encode($data);

$headers = array(
    "Content-Type: application/json", 
    "HTTP_X_MERCHANT_CODE: DOC",
);

$curl = curl_init($url);

curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($curl, CURLOPT_USERPWD, "dailyorders:dummyKey"); //Your credentials goes here
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false); //IMP if the url has https and you don't want to verify source certificate
curl_setopt($curl, CURLOPT_VERBOSE, true);

$curl_response = curl_exec($curl);
curl_close($curl);
echo $curl_response ."\n";

?>

【讨论】:

  • 谢谢,是的,它显示 401,所以我解码并获得了用户名和密码,我将上面的代码替换为 curl_setopt($curl, CURLOPT_USERPWD, "dailyorders:dummyKey");,现在我得到 {"response":[{"status":"REQUEST_REJECTED","message":["X_Merchant_Code is null "]}],"request_id":"b03e36cd-a9d8-4ac8-bb6d-0cc3b211a13d"},但我在参数中传递了 Merchant code ......这里是link
  • 我对此无能为力,因为我没有凭证。
  • 我发布了带有暂存凭据的 php 代码.....请尝试从 localhost 或仅在您的服务器中......
  • 好的,如果您信任我,我会试一试,但请务必尽快更改您的凭据。
  • 我想我已经成功地得到了回复,我明天会更新我的答案:)
【解决方案4】:

以正确的形式传递商户密钥解决了这个问题....

$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => "https://staging.ekartlogistics.com/v2/shipments/create",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => "",
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 30,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_POSTFIELDS => "{\n  \"request_id\": 835,\n  \"client_name\": \"DOC\",\n  \"services\": [\n    {\n      \"service_code\": \"REGULAR\",\n      \"service_details\": [\n        {\n          \"service_leg\": \"FORWARD\",\n          \"service_data\": {\n            \"vendor_name\": \"Ekart\",\n            \"amount_to_collect\": \"5382.00\",\n            \"delivery_type\": \"SMALL\",\n            \"source\": {\n              \"address\": {\n                \"first_name\": \"Ebay\",\n                \"address_line1\": \"sqsq\",\n                \"address_line2\": \"gvhvh\",\n                \"pincode\": \"110037\",\n                \"city\": \"gvhbj\",\n                \"state\": \"Delhi\",\n                \"primary_contact_number\": \"9987654321\"\n              }\n            },\n            \"destination\": {\n              \"address\": {\n                \"first_name\": \"Dgwdh\",\n                \"address_line1\": \"C-238\",\n                \"address_line2\": \"Nagar, Amrut Nagar, Ghatkopar (W)\",\n                \"pincode\": \"560034\",\n                \"city\": \"Delhi\",\n                \"state\": \"South West Delhi\",\n                \"primary_contact_number\": \"9716632816\"\n              }\n            },\n            \"return_location\": {\n              \"address\": {\n                \"first_name\": \"Primasource Products and \",\n                \"address_line1\": \"No 99 4th Cross , Prithvi Layout\",\n                \"address_line2\": \"ECC Raod\",\n                \"pincode\": \"560034\",\n                \"city\": \"Bangalore\",\n                \"state\": \"Karnataka\",\n                \"primary_contact_number\": \"9987654321\"\n              }\n            }\n          },\n          \"shipment\": {\n            \"tracking_id\": \"DOCC0000000837\",\n            \"shipment_value\": 2000,\n            \"shipment_dimensions\": {\n              \"length\": {\n                \"value\": \"12\"\n              },\n              \"breadth\": {\n                \"value\": \"12\"\n              },\n              \"height\": {\n                \"value\": \"12\"\n              },\n              \"weight\": {\n                \"value\": \"1\"\n              }\n            },\n            \"return_label_desc_1\": \"\",\n            \"return_label_desc_2\": \"\",\n            \"shipment_items\": [\n              {\n                \"product_id\": \"895\",\n                \"product_title\": \"dwdwd\",\n                \"quantity\": 23,\n                \"cost\": {\n                  \"total_sale_value\": \"5382.00\",\n                  \"total_tax_value\": 5382,\n                  \"tax_breakup\": {\n                    \"cgst\": 0,\n                    \"sgst\": 0,\n                    \"igst\": 0\n                  }\n                },\n                \"seller_details\": {\n                  \"seller_reg_name\": \"Ebay\",\n                  \"vat_id\": \"\",\n                  \"cst_id\": \"\",\n                  \"tin_id\": \"\",\n                  \"gstin_id\": null\n                },\n                \"hsn\": \"123456\",\n                \"ern\": \"\",\n                \"discount\": \"0.00\",\n                \"item_attributes\": [\n                  {\n                    \"name\": \"order_id\",\n                    \"value\": 835\n                  },\n                  {\n                    \"name\": \"invoice_id\",\n                    \"value\": \"NA\"\n                  },\n                  {\n                    \"name\": \"item_dimensions\",\n                    \"value\": \":\"\n                  },\n                  {\n                    \"name\": \"brand_name\",\n                    \"value\": null\n                  }\n                ]\n              }\n            ]\n          }\n        }\n      ]\n    }\n  ]\n}",
  CURLOPT_HTTPHEADER => array(
    "Content-Type: application/json",
    "HTTP_X_MERCHANT_CODE: DOC",
    "Authorization: Basic ZGFpbHlvcmRlcnM6ZHVtbXlLZXk=",
    "Postman-Token: bf0fd969-0618-432a-a222-d4a67bff6cd2",
    "cache-control: no-cache"
  ),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

【讨论】:

  • 啊,我认为标头 http x 商家代码解决了你的问题。
猜你喜欢
  • 2013-08-13
  • 1970-01-01
  • 2021-03-30
  • 1970-01-01
  • 2016-04-10
  • 1970-01-01
  • 2021-07-15
  • 2013-11-01
  • 2018-09-17
相关资源
最近更新 更多