php 发送POST 请求

  1. /**  
  2.  * Curl版本  
  3.  * 使用方法:  
  4.  * $post_string = "app=request&version=beta";  
  5.  * request_by_curl('http://www.qianyunlai.com/restServer.php', $post_string);  
  6.  */  
  7. function request_by_curl($remote_server, $post_string) {  
  8.   $ch = curl_init();  
  9.   curl_setopt($ch, CURLOPT_URL, $remote_server);  
  10.   curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);  
  11.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
  12.   curl_setopt($ch, CURLOPT_USERAGENT, "qianyunlai.com's CURL Example beta");  
  13.   $data = curl_exec($ch);  
  14.   curl_close($ch);  
  15.   
  16.   return $data; 
posted @ 2015-06-24 09:00  dcj890828  阅读(99)  评论(0编辑  收藏  举报