Jump to content

send request using curl


homer.favenir

Recommended Posts

hi everyone,

 

can you please kindly check my code for error

 

$xmltosend = "<?xml version='1.0'?>\r\n".
"<soap:Envelope xmlns:soap='http://www.w3.org/2001/12/soap-envelope' soap:encodingStyle='http://www.w3.org/2001/12/soap-encoding'>\r\n".
"<soap:Body xmlns:m='https://www.trustwave.com/'>\r\n".
"<request>\n". 
"<authentication>\n". 
"<username>username</username>\n". 
"<password>password</password>\n". 
"</authentication>\n". 
"<operation>getResellerProducts</operation>\n". 	
"<params>\n". 
	"<int>12345</int>\n". 
"</params>\n". 
"</request>\n".
"</soap:Envelope>\n";

$reqheader = "POST /index.php HTTP/1.1\r\n".
"Host:www.trustwave.com\r\n".
"Content-Type: application/soap+xml; charset=utf-8\r\n".
"Content-Length: ".strlen($xmltosend) ."\r\n\r\n";


$url = 'https://testapi.ssl.trustwave.com/3.0/';
// fake - obviosly!

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xmltosend); 
curl_setopt($ch, CURLOPT_POST, true);
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $reqheader);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");

$result = curl_exec($ch);
curl_close($ch);

print $result;

 

im getting this error

 

Authorization Required

This server could not verify that you are authorized to access the document requested. Either you supplied the wrong credentials (e.g., bad password), or your browser doesn't understand how to supply the credentials required.

 

anyone pleeeaassseee...!!! :shrug:

 

tia ;)

Link to comment
https://forums.phpfreaks.com/topic/259977-send-request-using-curl/
Share on other sites

thanks for the reply,

the username and password given by the administrator is correct.

 

updated code

<?php
$url = 'https://testapi.ssl.trustwave.com/3.0/';
$xmltosend = "<?xml version='1.0' encoding='UTF-8'?>\n".
"<soap:Envelope xmlns:soap='http://www.w3.org/2001/12/soap-envelope' soap:encodingStyle='http://www.w3.org/2001/12/soap-encoding'>\n".
"<soap:Body xmlns:m='https://testapi.ssl.trustwave.com/3.0/'>\n".
"<request>\n". 
"<authentication>\n". 
"<username>username</username>\n". 
"<password>password</password>\n". 
"</authentication>\n". 
"<operation>getResellerProducts</operation>\n". 
"<params>\n". 
	"<int>12345</int>\n". 
"</params>\n". 
"</request>\n".
"</soap:Body>\n".
"</soap:Envelope>\n";
$reqheader = "POST /index.php HTTP/1.1\r\n".
"Host:www.trustwave.com\r\n".
"Content-Type: application/soap+xml; charset=utf-8\r\n".
"Content-Length: ".strlen($xmltosend) ."\r\n\r\n";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS,$xmltosend);
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $reqheader);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");
$result = curl_exec($ch);
if($result === false)
{
    echo 'Curl error: ' . curl_error($ch);
}
else
{
    echo 'Operation completed without any errors';
}
curl_close($ch);
print $result;
?>

 

i cant find the error...ive been searching the net but found no concrete solutions...:(

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.