PHP fsockopen卷曲转换

前端之家收集整理的这篇文章主要介绍了PHP fsockopen卷曲转换前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有这段代码
<?PHP $host = "registration.mypengo.com";
$request = "/webregistration.aspx?taskaction=serviceresponse&partner=157&subid=" . $subid . "&msisdn=" . $msisdn . "&type=TEXT&data=" . $data . "&serviceid=" . $service_id;
$fp = fsockopen($host,80,$errno,$errstr,3.0);

if($fp)
{
  fwrite($fp,"GET $request HTTP/1.0\r\n" .
    "Host: $host\r\n".
    "Connection: close\r\n".
    "Content-Length: " . strlen($request) . "\r\n" .
    "\r\n" .
  $request);

  stream_set_timeout($fp,2,0);
  $response = "";

  while(!feof($fp))
    $response .= fread($fp,1024);

  fclose($fp);?>

我想尝试使用卷曲,但我有点卷曲,所以任何人都可以分享一些想法吗?

这相当于使用cURL,
$ch = curl_init(); 
    curl_setopt($ch,CURLOPT_URL,"http://" . $host . $request); 
    curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); 
    curl_setopt($ch,CURLOPT_HTTP_VERSION,CURL_HTTP_VERSION_1_0);
    curl_setopt($ch,CURLOPT_HTTPHEADER,array('Connection: close'));
    curl_setopt($ch,CURLOPT_TIMEOUT,2); 
    $response = curl_exec($ch); 
    curl_close($ch);

顺便说一下,像这样制作查询字符串是不安全的.您应该使用http_build_query()来构建它,以便正确编码.

原文链接:https://www.f2er.com/php/138264.html

猜你在找的PHP相关文章