[PHP] PHP模拟POST、GET请求 →→→→→进入此内容的聊天室

来自 , 2021-03-23, 写在 PHP, 查看 138 次.
URL http://www.code666.cn/view/d1c373ab
  1. if(function_exists('curl_init'))
  2. {
  3.   $ch = curl_init();
  4.   curl_setopt($ch, CURLOPT_URL, $url_with_get);
  5.   curl_setopt($ch, CURLOPT_POST, 1);
  6.   curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
  7.   curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  8.   $result = curl_exec($ch);
  9.   curl_close($ch);
  10. }
  11. else
  12. {
  13.   $content = http_build_query($post)
  14.   $content_length = strlen($content);
  15.   $context =
  16.         array('http' =>
  17.               array('method' => 'POST',
  18.                     'user_agent' => $user_agent,
  19.                     'header' => 'Content-Type: ' . $content_type . "\r\n" .
  20.                                 'Content-Length: ' . $content_length,
  21.                     'content' => $content));
  22.     $context_id = stream_context_create($context);
  23.     $sock = fopen($url_with_get, 'r', false, $context_id);
  24.     $result = '';
  25.     if ($sock)
  26.   {
  27.     while (!feof($sock))
  28.           $result .= fgets($sock, 4096);
  29.         fclose($sock);
  30.     }
  31.     return $result;
  32.   }
  33. }
  34.  

回复 "PHP模拟POST、GET请求"

这儿你可以回复上面这条便签

captcha