Jump to content

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

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.