字体:  

请教个HTTP响应的问题

spiritxia 发表于: 2008-9-08 11:56 来源: PHPChina 开源社区门户

可能我表达的不是很清楚,没接触过这一块

现在有需求,需要通过某个接口发送短信

请问我在PHP中该如何请求?

比如 接口为 http://interface

发送成功的话会返回200响应码,失败的话会返回400

请问我如何用PHP处理这个请求,并接受请求结果,并根据不同结果走不通流程呢?

实现如:

结果 = 请求(接口)
switch(结果)
{
   case '200':
              .....
   case '400':
             .....
}

最新回复

xuer at 2008-9-08 12:00:55
可以使用get_headers来取得HTTP状态,具体用法请查阅PHP手册即可得知
于安 at 2008-9-08 12:08:26
<?
$f=get_headers('http://www.fenanr.com');
print_r($f);
?>
----------------------------------
Array
(
    [0] => HTTP/1.1 200 OK
    [1] => Connection: close
    [2] => Date: Mon, 08 Sep 2008 04:07:40 GMT
    [3] => Server: Microsoft-IIS/6.0
    [4] => X-Powered-By: ASP.NET
    [5] => X-Powered-By: PHP/4.4.4
    [6] => Expires: 0
    [7] => Cache-Control: private, post-check=0, pre-check=0, max-age=0
    [8] => Pragma: no-cache
    [9] => Set-Cookie: lec_sid=KQCv7N; expires=Mon, 15 Sep 2008 04:07:40 GMT; path=/
    [10] => Set-Cookie: lec_onlineusernum=34; expires=Mon, 08 Sep 2008 04:12:40 GMT; path=/
    [11] => Content-type: text/html
)
学习了..
spiritxia at 2008-9-08 12:16:24
ok thanks
action2001 at 2008-9-08 15:26:26
学习...
阿米 at 2008-9-08 15:27:48
spiritxia at 2008-9-08 17:32:46
有没有办法只得到比如400这样的状态码呢