Jump to content

api request


homer.favenir

Recommended Posts

hi, can anyone please check my code

 

it has an error

invalid content type for request: application/x-www-form-urlencoded

 

<?php
$request = "<?xml version='1.0'?><request><br>
<authentication><br>
<username>username</username><br>
<password>password</password><br>
</authentication><br>
<operation>getResellerProducts</operation><br>
<params><br>
<int>22</int><br>
</params><br>
</request></myXML>
";

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

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);

print $result;
?>

 

thanks!

Link to comment
https://forums.phpfreaks.com/topic/258464-api-request/
Share on other sites

hi, thanks for the reply, how am i going to use the curlopt_httpheader for this particular request?

 

btw is this the correct format?

 

<?php
$request = "<?xml version='1.0'?><request>
<authentication>
<username>username</username>
<password>password</password>
</authentication>
<operation>getResellerProducts</operation>
<params>
<int>22</int>
</params>
</request>";

$url = urlencode( "https://testapi.ssl.trustwave.com/3.0/");  
// fake - obviosly!

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request); 
// what to post
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$result = curl_exec($ch);
curl_close($ch);

print $result;
?>

 

 

tia

Link to comment
https://forums.phpfreaks.com/topic/258464-api-request/#findComment-1325024
Share on other sites

Request

Parameter: rsId
Datatype: Integer
Required: Yes
Description: The reseller id
Expected request:
<request>
<authentication>
<username>username</username>
<password>password</password>
</authentication>
<operation>getResellerProducts</operation>
<params>
<int>22</int>
</params>
</request>

this is one of the part of the documentation.

question is how am i going to use it to get the response?

 

i searched the net and got the code above.

but it returns no error but blank white webpage

 

tia

Link to comment
https://forums.phpfreaks.com/topic/258464-api-request/#findComment-1325106
Share on other sites

hi,

 

i tried curl

$request = 'URL';
$method = 'myMethod';
$username = 'myusername';
$password = 'mypassword';
$rsId = 12345;
$postargs = 'operation='.$method.'&rsId='.$rsId;

$postFields = $postargs;
$ch = curl_init($request);
curl_setopt($ch, CURLOPT_URL, $request);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERPWD, "myUsername:myPassword");
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
$result = curl_exec($ch);
   curl_close($ch);
   print_r($result);

 

but the result is blank, all blank page.

 

anyone please guide me

 

thanks in advance

 

Link to comment
https://forums.phpfreaks.com/topic/258464-api-request/#findComment-1325296
Share on other sites

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.