简体   繁体   中英

Curl response not getting result data

I am trying to send WSDL through curl. But I am getting the below response:

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

My code is below:

    $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);
        }

after doing some R&D i have troubleshoot the problem. there is problem in curl lines,after edit the curl code my WSDL working fine

below is working code

$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);
        }    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM