2010-10-06 106 views

回答

11

这可能工作的东西,给它一个镜头。

 
$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/

+0

感谢的链接解释了很多 – wael34218 2010-10-06 14:05:30

+0

的联系是完美的!你可以更新你的答案,至少有curl_setopt($ ch,CURLOPT_SSL_VERIFYPEER,false); line – rsc 2014-10-08 07:35:36

1

Zend Framework有一个名为Zend_Http_Client一个很好的组件,它是完美的这种交易。

在底层,它使用curl来发出请求,但是你会发现Zend_Http_Client有更好的接口可以使用,并且当你想添加自定义头文件或者处理响应时更容易配置。

如果你想要做的是检索与最小的工作页面的内容,你可能能够做到以下几点,根据服务器的配置:

$data = file_get_contents('https://www.example.com/'); 
+0

404 ........................... – Pacerier 2017-11-22 18:03:10

+0

更新了链接 – 2017-11-22 22:43:40

0

示例如何使用的HttpRequest发布数据接收响应:

<?php 
//set up variables 
$theData = '<?xml version="1.0"?> 
<note> 
    <to>my brother</to> 
    <from>me</from> 
    <heading>hello</heading> 
    <body>this is my body</body> 
</note>'; 
$url = 'http://www.example.com'; 
$credentials = '[email protected]:password'; 
$header_array = array('Expect' => '', 
       'From' => 'User A'); 
$ssl_array = array('version' => SSL_VERSION_SSLv3); 
$options = array(headers => $header_array, 
       httpauth => $credentials, 
       httpauthtype => HTTP_AUTH_BASIC, 
      protocol => HTTP_VERSION_1_1, 
      ssl => $ssl_array); 

//create the httprequest object    
$httpRequest_OBJ = new httpRequest($url, HTTP_METH_POST, $options); 
//add the content type 
$httpRequest_OBJ->setContentType = 'Content-Type: text/xml'; 
//add the raw post data 
$httpRequest_OBJ->setRawPostData ($theData); 
//send the http request 
$result = $httpRequest_OBJ->send(); 
//print out the result 
echo "<pre>"; print_r($result); echo "</pre>"; 
?> 
-1

有2个示例GET方法和POST方法

GET例如:

<?php 
$r = new HttpRequest('http://example.com/feed.rss', HttpRequest::METH_GET); 
$r->setOptions(array('lastmodified' => filemtime('local.rss'))); 
$r->addQueryData(array('category' => 3)); 
try { 
    $r->send(); 
    if ($r->getResponseCode() == 200) { 
     file_put_contents('local.rss', $r->getResponseBody()); 
    } 
} catch (HttpException $ex) { 
    echo $ex; 
} 
?> 

邮政例

<?php 
$r = new HttpRequest('http://example.com/form.php', HttpRequest::METH_POST); 
$r->setOptions(array('cookies' => array('lang' => 'de'))); 
$r->addPostFields(array('user' => 'mike', 'pass' => 's3c|r3t')); 
$r->addPostFile('image', 'profile.jpg', 'image/jpeg'); 
try { 
    echo $r->send()->getBody(); 
} catch (HttpException $ex) { 
    echo $ex; 
} 
?> 
+1

OP询问'HTTPS' – jimasun 2017-01-10 15:01:40

相关问题