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
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...:(

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.