命令行curl到PHP curl问题(500服务器错误)
我连接到一个带有多部分/表单数据的API,如果我在命令行上通过curl发送请求,我没有问题,但是当使用PHP curl发送请求时,我得到一个内部服务器500错误 命令行是命令行curl到PHP curl问题(500服务器错误),php,curl,command-line,Php,Curl,Command Line,我连接到一个带有多部分/表单数据的API,如果我在命令行上通过curl发送请求,我没有问题,但是当使用PHP curl发送请求时,我得到一个内部服务器500错误 命令行是 curl -H "Content-Type: multipart/form-data" -H "X-DevKey: XXX" -H "X-AccessToken: XXX" -F "data=@file.json; type=application/json" -X POST https://api.site.com/v1/I
curl -H "Content-Type: multipart/form-data" -H "X-DevKey: XXX" -H "X-AccessToken: XXX" -F "data=@file.json; type=application/json" -X POST https://api.site.com/v1/Items -i -v
那么,给我以下的回答
> POST /v1/Items HTTP/1.1
> User-Agent: curl/7.24.0 (x86_64-apple-darwin12.0) libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
> Host: api.site.com
> Accept: */*
> X-DevKey: XXX
> X-AccessToken: XXX
> Content-Length: 1008
> Expect: 100-continue
> Content-Type: multipart/form-data; boundary=----------------------------58bf5d52327e
>
< HTTP/1.1 100 Continue
HTTP/1.1 100 Continue
< Set-Cookie: sto-id=XXX; Expires=Fri, 16-May-2025 15:32:27 GMT; Path=/
Set-Cookie: sto-id=XXX; Expires=Fri, 16-May-2025 15:32:27 GMT; Path=/
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< Cache-Control: no-cache
Cache-Control: no-cache
< Pragma: no-cache
Pragma: no-cache
< Content-Type: application/json; charset=utf-8
Content-Type: application/json; charset=utf-8
< Expires: -1
Expires: -1
< X-Powered-By: ASP.NET
X-Powered-By: ASP.NET
< Date: Tue, 19 May 2015 15:32:28 GMT
Date: Tue, 19 May 2015 15:32:28 GMT
< Content-Length: 220
Content-Length: 220
< Set-Cookie: sto-id=XXX; Expires=Fri, 16-May-2025 15:32:28 GMT; Path=/
Set-Cookie: sto-id=XXX; Expires=Fri, 16-May-2025 15:32:28 GMT; Path=/
<
* Connection #0 to host api.site.com left intact
{"userMessage":"Item listed with itemID: 484495200","developerMessage":"Item listed with itemID: 484495200","links":[{"rel":"self","href":"https://api.site.com/v1/items/484495200","verb":"GET","title":"484495200"}]}* Closing connection #0
## Heading ##* SSLv3, TLS alert, Client hello (1):
>POST/v1/Items HTTP/1.1
>用户代理:curl/7.24.0(x86_64-apple-darwin12.0)libcurl/7.24.0 OpenSSL/0.9.8y zlib/1.2.5
>主持人:api.site.com
>接受:*/*
>X-DevKey:XXX
>X-AccessToken:XXX
>内容长度:1008
>预期:100人继续
>内容类型:多部分/表单数据;边界=------------------------------------58bf5d52327e
>
我当前的PHP函数如下所示
function create_listing($buynow, $startingBid, $category, $description, $picture, $sku, $title)
{
$url = "https://api.site.com/v1/Items";
$token = get_access_token();
$headers = array(
"X-DevKey: XXX",
"X-AccessToken: $token",
"Expect: 100-continue",
"Content-Type: multipart/form-data; Boundary=----WebKitFormBoundaryR7f7XrG1vJhOfHzu"
);
$data = array(
"AutoRelist" => 1,
"AutoRelistFixedCount" => 0,
"BuyNowPrice" => 9.99,
"CategoryID" => 2325,
"Condition" => 1,
"CountryCode" => 'US',
"Description" => $description,
"InspectionPeriod" => 1,
//"FixedPrice" => $fixedprice,
"IsFFLRequired" => true,
"ListingDuration" => 1,
"PaymentMethods" => array(
"Check" => false,
"VisaMastercard" => true,
"COD" => false,
"Escrow" => false,
"Amex" => false,
"PayPal" => false,
"Discover" => true,
"SeeItemDesc" => true,
"CertifiedCheck" => true,
"USPSMoneyOrder" => true,
"MoneyOrder" => false
),
"PostalCode" => '85388',
"Quantity" => 1,
//"ReservePrice" => $reserve,
"SalesTaxes" => array(
array(
"State" => 'AZ',
"TaxRate" => 8.5
)
),
//"SerialNumber" => $serial,
"ShippingClassCosts" => array(
"Ground" => 25.00,
"Priority" => 25.00
),
"ShippingClassesSupported" => array(
"Overnight" => false,
"TwoDay" => false,
"ThreeDay" => false,
"Ground" => true,
"FirstClass" => false,
"Priority" => true,
"Other" => false
),
//"ShippingProfileID" => $shippingProfile,
"SKU" => $sku,
"StartingBid" => 0.99,
"Title" => $title,
//"UPC" => $upc,
//"Weight" => $weight,
//"WeightUnit" => 1,
"WhoPaysForShipping" => 8,
//"ItemPremiumFeatures" => array(
//
//),
"WillShipInternational" => false
);
$boundary = '----WebKitFormBoundaryR7f7XrG1vJhOfHzu';
$request = "$boundary\nContent-Disposition: form-data; name=\"data\"\n";
$request .= json_encode($data) . "\n$boundary--";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
$verbose = fopen('php://temp', 'rw+');
curl_setopt($ch, CURLOPT_STDERR, $verbose);
$result = curl_exec($ch);
if ($result === FALSE) {
printf("cUrl error (#%d): %s<br>\n", curl_errno($ch),
htmlspecialchars(curl_error($ch)));
}
rewind($verbose);
$verboseLog = stream_get_contents($verbose);
echo "Verbose information:\n<pre>", htmlspecialchars($verboseLog), "</pre>\n";
$info = curl_getinfo($ch);
if (!$result) {
echo curl_error($ch);
}
curl_close($ch);
return $result;
}
函数创建\u列表($buynow、$startingBid、$category、$description、$picture、$sku、$title)
{
$url=”https://api.site.com/v1/Items";
$token=get_access_token();
$headers=数组(
“X-DevKey:XXX”,
“X-AccessToken:$token”,
“期望:100继续”,
“内容类型:多部分/表单数据;边界=---WebKitFormBoundaryR7F7XRG1VJHOFZU”
);
$data=数组(
“自动列表”=>1,
“AutoRelistFixedCount”=>0,
“BuyNowPrice”=>9.99,
“类别ID”=>2325,
“条件”=>1,
“国家代码”=>“美国”,
“Description”=>$Description,
“检查周期”=>1,
//“固定价格”=>$FixedPrice,
“isfflequired”=>true,
“ListingDuration”=>1,
“PaymentMethods”=>数组(
“Check”=>false,
“VisaMastercard”=>正确,
“COD”=>错误,
“托管”=>错误,
“美国运通”=>错误,
“贝宝”=>错误,
“发现”=>正确,
“SeeItemDesc”=>正确,
“CertifiedCheck”=>正确,
“USPSMoneyOrder”=>正确,
“MoneyOrder”=>错误
),
“PostalCode”=>“85388”,
“数量”=>1,
//“ReservePrice”=>$reserve,
“销售税”=>数组(
排列(
“州”=>“AZ”,
“税率”=>8.5
)
),
//“SerialNumber”=>$serial,
“ShippingClassCosts”=>数组(
“地面”=>25.00,
“优先级”=>25.00
),
“ShippingClassesSupported”=>数组(
“隔夜”=>错误,
“两天”=>错误,
“三天”=>错误,
“地面”=>正确,
“头等舱”=>错误,
“优先级”=>正确,
“其他”=>错误
),
//“ShippingProfileID”=>$shippingProfile,
“SKU”=>$SKU,
“StartingBid”=>0.99,
“Title”=>$Title,
//“UPC”=>$UPC,
//“重量”=>$Weight,
//“重量单位”=>1,
“谁为装运付款”=>8,
//“ItemPremiumFeatures”=>数组(
//
//),
“WillShipInternational”=>错误
);
$boundary='---webkitformboundaryr7f7xrg1vjhofzhu';
$request=“$boundary\n内容处置:表单数据;名称=\”数据\“\n”;
$request.=json_encode($data)。“\n$boundary--”;
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$URL);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
卷曲设置($ch,卷曲设置桩,1);
curl_setopt($ch,CURLOPT_VERBOSE,true);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_POSTFIELDS,$request);
curl_setopt($ch,CURLOPT_CUSTOMREQUEST,“POST”);
curl_setopt($ch,CURLOPT_COOKIEFILE,'cookie.txt');
curl_setopt($ch,CURLOPT_COOKIEJAR,'cookie.txt');
$verbose=fopen('php://temp","rw+",;
curl_setopt($ch,CURLOPT_STDERR,$verbose);
$result=curl\u exec($ch);
如果($result==FALSE){
printf(“旋度误差(#%d):%s
\n”,旋度误差($ch),
htmlspecialchars(卷曲误差($ch));
}
倒带($verbose);
$verboseLog=stream\u get\u contents($verbose);
回显“详细信息:\n”,htmlspecialchars($verboseLog),“\n”;
> POST /v1/Items HTTP/1.1
Host: api.site.com
Accept: */*
Cookie: sto-id=JKHHNMED
X-DevKey: XXX
X-AccessToken: XXX
Expect: 100-continue
Content-Type: multipart/form-data; Boundary=----WebKitFormBoundaryR7f7XrG1vJhOfHzu
Content-Length: 939
< HTTP/1.1 100 Continue
< HTTP/1.1 500 Internal Server Error
< Cache-Control: no-cache
< Pragma: no-cache
< Content-Type: application/json; charset=utf-8
< Expires: -1
< X-Powered-By: ASP.NET
< Date: Tue, 19 May 2015 17:11:40 GMT
< Content-Length: 219
* HTTP error before end of send, stop sending
$info=curl\u getinfo($ch);
如果(!$result){
回波旋度误差($ch);
}
卷曲关闭($ch);
返回$result;
}
但我得到以下回应:
>POST/v1/Items HTTP/1.1
主持人:api.site.com
接受:*/*
Cookie:sto id=JKHHNMED
X-DevKey:XXX
X-AccessToken:XXX
预期:100人继续
内容类型:多部分/表单数据;边界=----WebKitFormBoundaryR7F7xRG1VJHOFZU
内容长度:939
任何关于我为什么会得到500错误的帮助都将不胜感激