file_get_contents提交http post get

来源:互联网 发布:三菱fx3ga编程手册 编辑:程序博客网 时间:2024/05/18 14:28

http://www.cnblogs.com/samson/archive/2011/08/12/2135834.html


POST

$data = array("name" => 'tim',"content" => 'test');   $data = http_build_query($data);   $opts = array(     'http'=>array(       'method'=>"POST",       'header'=>"Content-type: application/x-www-form-urlencoded\r\n".                 "Content-length:".strlen($data)."\r\n" .                  "Cookie: foo=bar\r\n" .                  "\r\n",       'content' => $data,     )   );   $cxContext = stream_context_create($opts);   $sFile = file_get_contents("http://localhost/response.php", false, $cxContext);



GET

$result = json_decode(file_get_contents($url));$data = json_encode(json_decode( json_encode( $result),true));


原创粉丝点击