通过PHP发出HTTPS请求并获得响应

wae*_*218 12 php https request

我想通过PHP向服务器发出HTTPS请求并获得响应.

类似于这个ruby代码的东西

  http = Net::HTTP.new("www.example.com", 443)

  http.use_ssl = true

  path = "uri"

  resp, data = http.get(path, nil)
Run Code Online (Sandbox Code Playgroud)

谢谢

saa*_*ulu 16

这可能会奏效,试一试.

 $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
// Set so curl_exec returns the result instead of outputting it.
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Get the response and close the channel.
$response = curl_exec($ch);
curl_close($ch);

了解更多信息,请查看 http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/