PHP http_response_code Get or Set the HTTP response code

PHP100 »  PHP教程 » Get or Set the HTTP response code

PHP http_response_code Get or Set the HTTP response code

http_response_code

(No version information available, might only be in SVN)

http_response_code — Get or Set the HTTP response code

说明

int http_response_code ([ int $response_code ] )

If you pass no parameters then http_response_code will get the current status code. If you pass a parameter it will set the response code.

参数

response_code

The optional response_code will set the response code.

<?php
http_response_code
(404);
?>

返回值

The current response code. By default the return value is int(200).

范例

Example #1 Examples using headers_list()

<?php

// Get the current default response code
var_dump(http_response_code()); // int(200)

// Set our response code
http_response_code(404);

// Get our new response code
var_dump(http_response_code()); // int(404)
?>

以上例程会输出:

参见

  • header() - Send a raw HTTP header
  • headers_list() - Returns a list of response headers sent (or ready to send)


PHP模拟POST请求,获取response内容

复制代码
 1     /*
 2      * 模拟POST请求,获取response内容
 3      */
 4     protected function curl($url, $type, $header, $data) {
 5         $CURL_OPTS = array (
 6                 CURLOPT_CONNECTTIMEOUT => 10,
 7                 CURLOPT_RETURNTRANSFER => true,
 8                 CURLOPT_SSL_VERIFYPEER => false,
 9                 CURLOPT_TIMEOUT => 60,
10                 CURLOPT_USERAGENT => 'simulate submit' 
11         );
12         $opts = $CURL_OPTS;
13         $opts [CURLOPT_URL] = $url;
14         $opts [CURLOPT_CUSTOMREQUEST] = $type;
15         $header [] = 'Expect:';
16         $opts [CURLOPT_HTTPHEADER] = $header;
17         if ($type == 'POST' || $type == 'PUT') {
18             $opts [CURLOPT_POSTFIELDS] = $data;
19         }
20         
21         $ch = curl_init ();
22         curl_setopt_array ( $ch, $opts );
23         $result = curl_exec ( $ch );
24         if (curl_errno ( $ch )) {
25             die ( 'CURL error: ' . curl_error ( $ch ) );
26         }
27         curl_close ( $ch );
28         return $result;
29     }
复制代码

参数: 

$header = array (
    'Content_type: application/x-www-form-urlencoded' 
  );

$data="param1=qwer&param2=asdf&param3=jkl";

分类:  PHP
0
0
(请您对文章做出评价)
« 上一篇: 解决360浏览器自动填充的屎黄色背景的问题
» 下一篇: Lucene.net 全文检索 盘古分词

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值