Trying to send data to a server which accepts data in the following format
VERIFY_DATA=MER_ID=xxx|MER_TRNX_ID=xxx| MER_TRNX_AMT=xxx
Will the fol开发者_开发百科lowing lines do?
$datatopost="VERIFY_DATA=MER_ID=xxx|MER_TRNX_ID=xxx| MER_TRNX_AMT=xxx";
curl_setopt ($ch, CURLOPT_POSTFIELDS,$datatopost);<br />
Any help will be appreciated,I am new with curl.
you can use this article to see how to do it properly.
I personally used this code to do it on a project of mine
$data="from=$from&to=$to&body=".urlencode($body)."&url=$url";
//$urlx contains the url where you want to post. $data contains the data you are posting
//$resp contains the response.
$process = curl_init($urlx);
curl_setopt($process, CURLOPT_HEADER, 0);
curl_setopt($process, CURLOPT_POSTFIELDS, $data);
curl_setopt($process, CURLOPT_POST, 1);
curl_setopt($process, CURLOPT_RETURNTRANSFER,1);
curl_setopt($process,CURLOPT_CONNECTTIMEOUT,1);
$resp = curl_exec($process);
curl_close($process);
here is a working example in php. This asks for and returns an FX quote. My data request is in the URL yours is in the post-fields though so you need to adjust. It looks as though you have spaces in the data you are passing "x| ME" i suspect it will not like that.
$ch = curl_init(); // initialise CURL
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $curl_opt_string ); // this contains the URL and the request
curl_setopt($ch, CURLOPT_HEADER, false); // no header
curl_setopt($ch, CURLOPT_INTERFACE, "93.129.141.79"); // where to send the data back to / outgoing network
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"); // tell it what the agent is
curl_setopt($ch, CURLOPT_POST, 1); // want the data back as a post
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // return as a string rather than to the screen
$output = curl_exec($ch); // varu=iable to return it to
curl_close($ch); // close cURL resource, and free up system resources
$subject = $output; // get the data
I constructed my output sting as follows
$curl_opt_string = "http://msxml.rexefore.com/index.php?username=MiJoee4r65&password=L8e44Y&instrument=245.20." . $lhsrhs . "LITE&fields=D4,D6";
精彩评论