I am trying to obtain a report from a website which actually has a login mechanism in it. So Far I have been able to do it and preserve the cookie in a file.
$url = 'https://<site>/action/method/blah';
$options = array(
'textUsername' => 'alpha',
'textPassword' => 'beta',
'appId' => 'gama',
'browser' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:41.0) Gecko/20100101 Firefox/41.0'
);
$cookie_file = APPPATH.'cookies/cookie.txt';
$postdata = http_build_query($options);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_URL, $url);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt ($ch, CURLOPT_USERAGENT, $options['browser']);
curl_setopt ($ch, CURLOPT_TIMEOUT, 60);
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_COOKIESESSION, true );
curl_setopt( $ch, CURLOPT_COOKIEJAR, $cookie_file );
curl_setopt( $ch, CURLOPT_COOKIEFILE, $cookie_file );
curl_setopt ($ch, CURLOPT_REFERER, $url);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt ($ch, CURLOPT_POST, 1);
$result = curl_exec ($ch);
echo $result;
curl_close($ch);
Now I want to extend this to fetch the report, I intercepted the original request in firefox and It looks contains the following.
Headers, Cookies, Query String, POST Data
In the Headers, It says that the request-type : SOAP
Cookie, Query String has key value pairs and POST Data has a XML doc.
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"><soap:Body>......
Can anyone help me to extend my existing code to send the request to fetch the report?
I need answers to the following questions.
Can we use the existing Curl handler $ch
to send the second SOAP
Request?
If Yes, How can we specify it to use the cookie file I created?
Also, How can I add the Query String and the XML POST
data in the request?
Any help would be much helpful.