Curl and Form Help
Posted: Fri Mar 02, 2007 11:05 am
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.
but when i submit i get.
Same as before.
So real question is how do you convert to the FormURLEncode
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";
?>Code: Select all
<RequestMPI><ErrorNo>2010</ErrorNo>
<ErrorDesc>Invalid Request Format: Empty Request</ErrorDesc>
</RequestMPI>So real question is how do you convert to the FormURLEncode