http请求第三方接口

  1. function send_post($url,$post_data) {  
  2.   
  3.   
  4.     $postdata = http_build_query($post_data);  
  5.     $options = array(  
  6.         'http' => array(  
  7.             'method' => 'POST',  
  8.             'header' => 'Content-type:application/x-www-form-urlencoded',  
  9.             'content' => $postdata,  
  10.             'timeout' => 15 * 60 // 超时时间(单位:s)  
  11.         )  
  12.     );  
  13.     $context = stream_context_create($options);  
  14.     $result = file_get_contents($url, false, $context);  
  15.   
  16.     return $result;  
  17. }  
  18.   
  19.   $order_number="订单号";  
  20.   
  21.   $post_data = array(  
  22.       'company_id' => '开放平台ID',  
  23.       'msg_type' => 'TRACEINTERFACE_NEW_TRACES',  
  24.       'data' => "[\"$order_number\"]",  
  25.       'data_digest' => '签名'  
  26.   );  
  27.   
  28. $data =send_post("http://japi.zto.cn/gateway.do",$post_data);  
  29.   
  30. echo $data;  

浏览器打印数据:

get:

[php]  view plain  copy
  1. $url='http://www.baidu.com/';  
  2. $html = file_get_contents($url);  
  3. echo $html;  

[php]  view plain  copy
  1. $searchUrl = 'URL?content=';  
  2. if(!empty($_GET['content']))  
  3. {  
  4.     $searchUrl .= $_GET['content'];  
  5. }  
  6. echo file_get_contents($searchUrl);  
 本文简单介绍了发送 HTTP 请求,项目中使用到的,就提写出来了,也方便自己以后查看。

猜你喜欢

转载自blog.csdn.net/dante_777/article/details/80363540