Curl and Form Help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Curl and Form Help

Post by oldtimer »

I am trying to use an API from a company and they tell me.

Your request needs to be a valid application/x-www-form-urlencoded message.
In short:
Set the content-type header to "application/x-www-form-urlencoded"
FormURLEncode the $datafield
POST the following for the data "cmpi_msg=$formEncodedData"

I made this code.

Code: Select all

<?
$queryString = "<REQUEST>";
$queryString = $queryString."<Version>1.6</Version>";
$queryString = $queryString."<MsgType>cmpi_msp_authenticate</MsgType>";
$queryString = $queryString."<Username>myuser</Username>";
$queryString = $queryString."<Password>abcdefg</Password>";
$queryString = $queryString."</REQUEST>";
$data=$queryString;
$this_header = array(
   "MIME-Version: 1.0",
   "Content-type: application/x-www-form-urlencoded; charset=iso-8859-1",
   "Content-transfer-encoding: application/x-www-form-urlencoded"
);
$LOGINURL = "$url";
$POSTFIELDS = "&cmpi_msg=$data"; 
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$LOGINURL);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
curl_setopt($ch, CURLOPT_POST, 1); 
curl_setopt($ch, CURLOPT_POSTFIELDS,$POSTFIELDS); 
curl_setopt($ch, CURLOPT_UNRESTRICTED_AUTH, 1); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANYSAFE); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $this_header);
$result = curl_exec ($ch);
curl_close ($ch); 
$mytest = $result;
$mytest2=htmlspecialchars($mytest);
$mytest2=nl2br($mytest2);
echo "$mytest2";
?>
but when i submit i get.

Code: Select all

<RequestMPI><ErrorNo>2010</ErrorNo>
<ErrorDesc>Invalid Request Format: Empty Request</ErrorDesc>
</RequestMPI>
Same as before.

So real question is how do you convert to the FormURLEncode

oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

I also just tried.

$data=urlencode($queryString);

no go still
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

$data and $queryString are never used in the code posted thus far.
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

yes it was .


$data=$queryString;
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you sniffed the http headers sent if you posted the form via a normal browser?
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

nope not sure how ot sniff headers.

I do have the sites people looking into it though. maybe they will come up with something.

i think i am the first person to try to integrate with them with php.
Post Reply