homer.favenir Posted March 7, 2012 Share Posted March 7, 2012 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 More sharing options...
ManiacDan Posted March 7, 2012 Share Posted March 7, 2012 The API you're posting to requires a specific content-type, and you are providing the wrong one. CURLOPT_HTTPHEADER is the option you must use to set the proper content type. Also, why is your XML all encoded like this? Link to comment https://forums.phpfreaks.com/topic/258464-api-request/#findComment-1324851 Share on other sites More sharing options...
homer.favenir Posted March 8, 2012 Author Share Posted March 8, 2012 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 More sharing options...
ManiacDan Posted March 8, 2012 Share Posted March 8, 2012 I have no idea what the correct format is, nor do I know what the correct header is...because of the two of us, only you have access to the documentation for this API. Link to comment https://forums.phpfreaks.com/topic/258464-api-request/#findComment-1325097 Share on other sites More sharing options...
homer.favenir Posted March 8, 2012 Author Share Posted March 8, 2012 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 More sharing options...
homer.favenir Posted March 8, 2012 Author Share Posted March 8, 2012 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.