PHP卷曲与多部分边界并与application / json和text / plain混合

时间:2015-01-27 16:30:42

标签: php api rest curl boundary

我尝试使用curl发布数据来休息api

我的参数是' appkey',' appsecret','数据' rest api允许appkey,appsecret的内容类型text / plain 并允许application / json用于数据

当我使用restClient软件时,即将成功响应。 但是当我使用php curl 500内部服务器错误时。

我的代码

<?php
$boundary= '--7ZAUH3KVUpvXgwagBLkB4v7r84QBpj0TxAvNF
Content-Disposition: form-data; name="appsecret"
Content-Type: text/plain; charset=UTF-8

xxxxxxxxxx
--7ZAUH3KVUpvXgwagBLkB4v7r84QBpj0TxAvNF
Content-Disposition: form-data; name="appkey"
Content-Type: text/plain; charset=UTF-8

xxxxxxxxxx
--7ZAUH3KVUpvXgwagBLkB4v7r84QBpj0TxAvNF
Content-Disposition: form-data; name="data"
Content-Type: application/json; charset=UTF-8
Content-Transfer-Encoding: 8bit

{"status":"New","buyerName":"","orderNumber":"","productId":"","productSellerCode":"","receipient":"","period":{"startDate":"01/01/2015 00:00","endDate":"27/01/2015 00:00"}}
--7ZAUH3KVUpvXgwagBLkB4v7r84QBpj0TxAvNF--';

$headers= array(
"Host: api.xxx.com",
"Content-Type: multipart/form-data; boundary=7ZAUH3KVUpvXgwagBLkB4v7r84QBpj0TxAvNF",
"User-Agent: Apache-HttpClient/4.2.1 (java 1.5)",
"Content-Length: " . strlen($boundary),
"Connection: Keep-Alive"
);

$curl = curl_init();

curl_setopt($curl, CURLOPT_URL, 'https://api.xxx.com/rest/secure/order/list.json');
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); 
curl_setopt($curl, CURLOPT_HEADER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER  ,1);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $boundary);

$response = curl_exec($curl);

print_r($response);

restClient配置在那里

http://tinypic.com/r/ifuctz/8

我该怎么办帖子字段用php curl来休息api

感谢您的回复。

0 个答案:

没有答案