Jump to content

Difference between CURL and HTTP POST


pranvkavi

Recommended Posts

For a particular SMS application, I am supposed to send the following XML content to an external URL.

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MESSAGE SYSTEM "http://127.0.0.1/psms/dtd/message.dtd" >
<MESSAGE>
<USER USERNAME="mycompany" PASSWORD="mycompany"/>
<SMS UDH="0" CODING="1" TEXT="hey this is a real test" PROPERTY="" ID="1"
DLR="0" VALIDITY="0">
<ADDRESS FROM="9812345678" TO="919812345678" SEQ="1" TAG="some
client side random data" />
</SMS>
</MESSAGE>

 

When I send it through a simple HTTP POST(form submit), it seems to work fine. The recipient(s) recieves the message. But if I replicate the same procedure through CURL, the external url gives that the XML send does not conform to DTD. The XML content is urlencoded before being sent through CURL.

 

Is there a difference between a CURL POST and a normal HTTP POST that can cause the above problem?? I could really use some help....

 

 

Link to comment
https://forums.phpfreaks.com/topic/201143-difference-between-curl-and-http-post/
Share on other sites

$data =  '%3C?xml%20version=%221.0%22%20encoding=%22ISO-8859-%22?%3E%3C!DOCTYPE%20 MESSAGE%20SYSTEM%20%22http://127.0.0.1/psms/dtd/messagev12.dtd.dtd%22%20%3E%3CMESSAGE%3E%3CUSER%20USERNAME=%22username%22%20PASWORD=%22XXXXX%22/%3E%3CSMS%20%20UDH=%220%22%20CODING=%221%22%20TEXT=%22The%20flight%20%23&btnG;%20<101>%20"DEL"%20to%20"BLR"%20is%20delayed%20and%20it's%20%20revised%20time%20will%20be%20informed%20later.%20Have%20a%20nice%20day!%22%20PROPERTY=%220%22%20ID=%221%22%3E%3CADDRESS%20FROM=%22919902202099%22%20TO=%22919886094024%22%20SEQ=%221%22%20TAG=%22some%20clientside%20random%20data%22%20/%3E%3C/SMS%3E%3C/MESSAGE%3E';
               
$url = "http://api.myvaluefirst.com/psms/servlet/psms.Eservice2";
$ch = curl_init();    // initialize curl handle
curl_setopt($ch, CURLOPT_URL,$url); // set url to post to
curl_setopt($ch, CURLOPT_FAILONERROR, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
curl_setopt($ch, CURLOPT_TIMEOUT, 5); // times out after 4s
curl_setopt($ch, CURLOPT_POST, 1); // set POST method
curl_setopt($ch, CURLOPT_POSTFIELDS, "data="+($data)+"&action=send"); // add POST fields
$result = curl_exec($ch); // run the whole process
curl_close($ch);
       
echo $result;

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.