PHP POST Curl头,如何将数组放入数组中



我通过API向另一个服务发送HTTPPost请求以创建订单。问题是,它需要一些数组中的HTTP参数。

这些是我现在使用的参数:

"Content-Type: application/json",
"Accept: application/json",
"Stream-Nonce:".$randomstring2,
"Stream-Party:***************",
"Authorization: bearer ".$result_array["access_token"],

我需要加上这个:

"header": {
"orderNo": "ABCD123456",
"orderDate": "2018-07-23",
"requiredDate": "2018-07-31",
"partner": {},
"orderType": "DELIVERY",
"serviceLevel": "STANDARD",
"services": [],
"customer": {},
"customerOrderNo": "ABC1234567890",
"orderNotes": "These notes relate to the order",
"driverNotes": "These notes are for the driver",
"routeInfo": "CC05"
},

这是直接来自我正在使用的服务文档。问题在于";标题":{…}.

我尝试了一种不同的数组格式,比如:

'Content-Type' => ' application/json',
'Accept' => ' application/json',
'Stream-Nonce' => ''.$randomstring2,
'Stream-Party' => '***************',
'Authorization' => ' bearer '.$result_array['access_token'],

在这种情况下,我相信进入=>数组('yada-yada'=>'yada'(;然而,在这样做之后,标头根本不起作用,我在发送请求时收到了禁止消息。

我在这里能做什么?谢谢

我读过go2stream文档。在使用guzzle时,这很容易。下面是一个例子
如果你遇到一些问题,大多数可能是错误的帖子数据
如果您有任何进一步的问题,请与我联系。

// composer require guzzlehttp/guzzle
$client = new GuzzleHttpClient();
$headers = [
// "Content-Type" => "application/json",
"Stream-Nonce" => $randomstring2,
"Stream-Party" => $streamParty,
"Authorization" => "bearer ".$result_array["access_token"],
];
$body = [
"header" =>  [
"orderNo" =>  "ABCD123456",
"orderDate" =>  "2018-07-23",
"requiredDate" =>  "2018-07-31",
"partner" =>  [],
"orderType" =>  "DELIVERY",
"serviceLevel" =>  "STANDARD",
"services" =>  [],
"customer" =>  [],
"customerOrderNo" =>  "ABC1234567890",
"orderNotes" =>  "These notes relate to the order",
"driverNotes" =>  "These notes are for the driver",
"routeInfo" =>  "CC05"
],
"collection" =>  [
"address" =>  [
"name" =>  "Proximity Resourcing Ltd",
"address1" =>  "6 Kerry Hill",
"address2" =>  "Off Town Street",
"address3" =>  "Horsforth",
"address4" =>  "Leeds",
"address5" =>  "West Yorkshire",
"country" =>  "GB",
"postcode" =>  "LS18 4AY",
"lat" =>  53.837496,
"long" =>  -1.640644,
"nuts" =>  "UKE42",
"locationNotes" =>  "These notes relate to the location"
],
"contact" =>  [
"name" =>  "Jane Contact",
"tel1" =>  "0113 000 0000",
"tel2" =>  "0113 000 0000",
"mobile" =>  "07801 000000",
"fax" =>  "0113 000 0000",
"email" =>  "sales@go2stream.com"
],
"required" =>  [
"fromDateTime" =>  "2018-07-31T12 => 00 => 00Z",
"toDateTime" =>  "2018-08-01T17 => 00 => 00Z"
],
"collectionMethod" =>  "NORTH",
"timeOnSite" =>  [
"unload" =>  60,
"assembly" =>  30
],
"bookingRequired" =>  true,
"items" =>  [
[
"sequence" =>  1,
"parentSequence" =>  2,
"code" =>  "ABC123",
"description" =>  "Widget",
"quantity" =>  10,
"weight" =>  150,
"cube" =>  3.5,
"assemblyTime" =>  30,
"stockLocation" =>  "LEEDS",
"onHandDate" =>  "2017-07-30",
"packageId" =>  "ABCD1234567890",
"notes" =>  "Include product manual within packaging.",
"packageType" =>  "PALLET"
]
]
]
];
$response = $client->request('POST',"https => //www.demo.go2stream.net/api/orders/orders",[
'headers' => $headers,
'json' => $body,
]);

最新更新