我正在尝试通过curl发送WSDL。但是我收到了以下回复:
HTTP/1.0 200 Connection established
HTTP/1.1 100 Continue
HTTP/1.1 500 Internal Server Error
Date: Sat, 02 May 2015 05:58:05 GMT
Server: IBM_HTTP_Server
X-Powered-By: Servlet/3.0
$WSEP:
Content-Length: 85
Content-Type: text/html;charset=ISO-8859-1
Connection: close
Content-Language: en-US
Error 500: java.lang.StringIndexOutOfBoundsException: String index out of range: -1
我的代码如下:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_PROXY, $proxy);
curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
// curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 50);
curl_setopt($ch, CURLOPT_TIMEOUT, 900);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, array("Content-type: text/xml;charset=\"utf-8\""));
// curl_setopt($ch, CURLOPT_HEADER, array("Content-Type: text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$curl_scraped_page = curl_exec($ch);
if ($curl_scraped_page === false) {
return 'Curl error: ' . curl_error($ch);
curl_close($ch);
} else {
return $curl_scraped_page;
curl_close($ch);
}
答案 0 :(得分:0)
下面是工作代码
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_PROXY, $proxy);
curl_setopt($curl, CURLOPT_PROXYUSERPWD, $proxyauth);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_TIMEOUT, 120);
curl_setopt($curl, CURLOPT_ENCODING, 'gzip');
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'SOAPAction:""',
'Content-Type: text/xml; charset=utf-8',
));
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$result = curl_exec($curl);
if ($result === false) {
return 'Curl error: ' . curl_error($curl);
curl_close($curl);
} else {
//convert xml into array
$xmlDoc = new MyDOMDocument();
$xmlDoc->loadXML($result);
return $xmlArray = $xmlDoc->toArray();
curl_close($curl);
}