国产一级a片免费看高清,亚洲熟女中文字幕在线视频,黄三级高清在线播放,免费黄色视频在线看

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
用PHP發(fā)送POST請(qǐng)求
  1. /**  

  2.  * 發(fā)送post請(qǐng)求  

  3.  * @param string $url 請(qǐng)求地址  

  4.  * @param array $post_data post鍵值對(duì)數(shù)據(jù)  

  5.  * @return string  

  6.  */  

  7. function send_post($url, $post_data) {   

  8.   $postdata = http_build_query($post_data);   


  9.   $options = array(   


  10.     'http' => array(   


  11.       'method' => 'POST',   


  12.       'header' => 'Content-type:application/x-www-form-urlencoded',   


  13.       'content' => $postdata,   


  14.       'timeout' => 15 * 60 // 超時(shí)時(shí)間(單位:s)   


  15.     )   


  16.   );   


  17.   $context = stream_context_create($options);   


  18.   $result = file_get_contents($url, false, $context);   


  19.   


  20.   return $result;   


  21. }   


  22.   


  23. //使用方法   


  24. $post_data = array(   


  25.   'username' => 'stclair2201',   


  26.   'password' => 'handan'  


  27. );   


  28. send_post('http://www.qianyunlai.com', $post_data);   


  29.   


  30.   


  31.   


  32.   


  33. <?php   


  34. /**  


  35.  * Socket版本  


  36.  * 使用方法:  


  37.  * $post_string = "app=socket&version=beta";  


  38.  * request_by_socket('chajia8.com', '/restServer.php', $post_string);  


  39.  */  


  40. function request_by_socket($remote_server,$remote_path,$post_string,$port = 80,$timeout = 30) {   


  41.   $socket = fsockopen($remote_server, $port, $errno, $errstr, $timeout);   


  42.   if (!$socket) die("$errstr($errno)");   


  43.   fwrite($socket, "POST $remote_path HTTP/1.0");   


  44.   fwrite($socket, "User-Agent: Socket Example");   


  45.   fwrite($socket, "HOST: $remote_server");   


  46.   fwrite($socket, "Content-type: application/x-www-form-urlencoded");   


  47.   fwrite($socket, "Content-length: " . (strlen($post_string) + 8) . "");   


  48.   fwrite($socket, "Accept:*/*");   


  49.   fwrite($socket, "");   


  50.   fwrite($socket, "mypost=$post_string");   


  51.   fwrite($socket, "");   


  52.   $header = "";   


  53.   while ($str = trim(fgets($socket, 4096))) {   


  54.     $header .= $str;   


  55.   }   


  56.   


  57.   $data = "";   


  58.   while (!feof($socket)) {   


  59.     $data .= fgets($socket, 4096);   


  60.   }   


  61.   


  62.   return $data;   


  63. }   


  64. ?>   


  65.   


  66. <?php   


  67. /**   


  68.  * Curl版本   


  69.  * 使用方法:   


  70.  * $post_string = "app=request&version=beta";   


  71.  * request_by_curl('http://www.qianyunlai.com/restServer.php', $post_string);   


  72.  */   


  73. function request_by_curl($remote_server, $post_string) {   


  74.   $ch = curl_init();   


  75.   curl_setopt($ch, CURLOPT_URL, $remote_server);   


  76.   curl_setopt($ch, CURLOPT_POSTFIELDS, 'mypost=' . $post_string);   


  77.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);   


  78.   curl_setopt($ch, CURLOPT_USERAGENT, "qianyunlai.com's CURL Example beta");   


  79.   $data = curl_exec($ch);   


  80.   curl_close($ch);   


  81.   


  82.   return $data;   


  83. }   


  84. ?>  

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
PHP中curl post的用法及原理解析
php curl實(shí)現(xiàn)get和post的代碼
Tutorial: FTP Upload via cURL | Web Developme...
php獲取通過(guò)http協(xié)議post提交過(guò)來(lái)xml數(shù)據(jù)及解析xml
phpcms2008 SQL注入漏洞(漏洞文件/c.php)
cURL超時(shí)設(shè)置
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服