php代码有什么问题?未知输出

时间:2013-07-24 12:22:59

标签: php api curl

PHP代码文件:sms1.php 位于http://techmentry.com/sms1.php(请访问该链接,查看以下代码的输出)。

<?php
//Variables to POST
$user = "HIDDEN";
$password = "HIDDEN";
$mobiles = "919999999999";
$message = "test";
$sender = "HIDDEN";

//Initialize CURL data to send via POST
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://example.com/example.php");
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=$user&

password=$password&
mobiles=$mobiles&
message=$message&
sender=$sender"
);

//Execute CURL command and return into variable $result
$result = curl_exec($ch);

//Do stuff
echo "$result"
?>

我期望的输出是:上面的代码应该处理这个URL:URL HIDDEN 然后返回消息ID或适当的错误代码。

但我得到的输出超出了我的预期!甚至没有错误日志。请帮帮我:)。

1 个答案:

答案 0 :(得分:0)

您可以获得代码,但您也可以从服务器获得完整的响应,包括HTTP标头。

我明白了:

HTTP/1.1 200 OK
Date: Wed, 24 Jul 2013 12:24:01 GMT
Server: Apache
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: max-age=60, private, proxy-revalidate
Pragma: no-cache
Vary: Accept-Encoding
Content-Length: 8
Content-Type: text/html
Set-Cookie: PHPSESSID=c9bfcf7ddd3fff9d0a05b34541fbf0a9; expires=Wed, 24-Jul-2013 16:24:01 GMT; path=/

code 105

尝试删除此行:

curl_setopt($ch, CURLOPT_HEADER, 1);