当我试图用php向服务器发送请求时,似乎出现了问题。 http api请求是这样的:
// XML
$xml_string = '<?xml version=\"1.0\" encoding=\"UTF-8\"?><PriceAvailabilityRequest><Header><MessageId>MSG-2018-12-10T10:18:07+0900</MessageId><Timestamp>2018-12-10T10:18:07+0900</Timestamp></Header><RequesterInfo><Customer code=\"APIKEY\"/><Location code=\"\"/><PreferredLanguage>EN</PreferredLanguage><PreferredCountry>DE</PreferredCountry></RequesterInfo><ProductRequest><SupplierPartNumber>00010-100G</SupplierPartNumber><UnitOfMeasure unit=\"EA\"/><Quantity>1</Quantity></ProductRequest></PriceAvailabilityRequest>';
// REST API URL
$url = 'https://webqws.sial.com/b2b?msgFmt=PriceAvailabilityRequest';
// header info
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\""
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
// send xml request to a server
curl_setopt ($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_VERBOSE, 0);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$data = curl_exec($ch);
$data = simplexml_load_string(stripslashes($data));
$info = curl_getinfo($ch);
curl_close($ch);
这是我从print_r(curl_getinfo($ ch))语句中得到的:
Array
(
[url] => https://webqws.sial.com/b2b?msgFmt=PriceAvailabilityRequest
[content_type] => text/xml;charset="utf-8"
[http_code] => 400
[header_size] => 1963
[request_size] => 323
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.558302
[namelookup_time] => 0.266533
[connect_time] => 0.268885
[pretransfer_time] => 0.286032
[size_upload] => 508
[size_download] => 508
[speed_download] => 910
[speed_upload] => 910
[download_content_length] => 508
[upload_content_length] => 508
[starttransfer_time] => 0.286037
[redirect_time] => 0
[redirect_url] =>
[primary_ip] => 184.25.83.215
[certinfo] => Array
(
)
[primary_port] => 443
[local_ip] => 223.26.138.3
[local_port] => 48054
)
我不确定解决方案是什么,我一直在研究这个问题已有一段时间了,希望有人可以帮助我:)