1

I am trying to send post request to a SMS api and receive the feedback from them using PHP and cURL .But, the cURL is not working for me ,when i try to send the same data through form it works.

$POST = array(
            'data' => $xml1

    );
$url = 'URL';
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url );
curl_setopt( $ch, CURLOPT_POST, true );
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch, CURLOPT_POSTFIELDS, $POST );
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
$result = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
echo "<input type=\"textarea\" id=\"txt\"  style='width:600px' value='$result'></input>";
echo "<input type=\"textarea\" id=\"txt1\" name='data1' style='width:600px' value='".$info['request_header']."'></input>";

And the XML IS

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE MESSAGE SYSTEM "http://127.0.0.1:80/psms/dtd/messagev12.dtd">
<MESSAGE VER="1.2">
<USER USERNAME="abc" PASSWORD="pqr" />
<SMS UDH="0" CODING="1" TEXT="SMS TEXT" PROPERTY="0" ID="1" TEMPLATE="" EMAILTEXT="" ATTACHMENT=""><ADDRESS FROM="someone" TO="91xxxxxxxxxx" EMAIL="" SEQ="1" TAG="some clientside random data"/>
</SMS>
</MESSAGE>

BUT USING FORM IT WORKS FINE ,CODE FOR FORM

echo "<form action=\"URL\" method=\"POST\" target=\"_blank\">";

    echo "<input type=\"textarea\" id=\"txt\" name='data' style='width:600px' value='$xml1'></input>";
    echo "<input type=\"SUBMIT\" name=\"action\" value=\"send\">";
    echo "</form>";

When I send data using form it shows Sent status but when i send using curl it shows output as :

    <?xml version="1.0" encoding="ISO-8859-1"?>
    <MESSAGEACK>
    <Err Code="65535" Desc="The Specified message does not conform to DTD"/>
</MESSAGEACK> 

Thanks

11
  • First difference I can see is that you are missing "action" => "send" in the curl $POST data. Your curl version also sets the request content-type header to "multipart/form-data" Commented Aug 21, 2017 at 6:41
  • @Phil I changed the content type to text/xml and added action = send ,but still its showing the same error Commented Aug 21, 2017 at 6:46
  • The <form> version would set the content-type to application/x-www-form-urlencoded, not text/xml Commented Aug 21, 2017 at 6:48
  • Try to set SSL_VERIFYPEER to false like curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); Commented Aug 21, 2017 at 6:49
  • @Phil tried that no luck Commented Aug 21, 2017 at 6:52

2 Answers 2

1

instead of creating array.

$POST = array('data' => $xml1);

Simply do $POST => $xml1

Sign up to request clarification or add additional context in comments.

Comments

0

How did you set $xml1 variable?

Make sure you used $xml1 = file_get_contents($xmlFilepath) istead of simplexml_load_file($xmlFilepath)

4 Comments

i generated xml dynamically using php and mysql so $xml1 is just a variable containing xml
So, $xml1 data type is SimpleXMLElement object or string?
its string not SimpleXMLElement Object
try this line: {curl_setopt( $ch, CURLOPT_POSTFIELDS, "data=".$xml1."&action=send" );} .

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.