2010-10-06 16 views

risposta

11

questo potrebbe funzionare, dare un colpo.

 
$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); 

per ulteriori informazioni, controllare http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/

+0

grazie link spiegato molto – wael34218

+0

Il link è stato perfetto! Potresti aggiornare la tua risposta per avere almeno il curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false); linea – rsc

1

Il Zend Framework ha una bella componente chiamato Zend_Http_Client che è perfetto per questo tipo di operazioni.

Sotto il cofano si utilizza curl di effettuare le richieste, ma troverete Zend_Http_Client ha un'interfaccia molto più bello di lavorare con ed è più facile da configurare quando si desidera aggiungere intestazioni personalizzate o di lavoro con le risposte.

Se tutto quello che vogliamo fare è recuperare il contenuto della pagina con un lavoro minimo, si può essere in grado di effettuare le seguenti operazioni, a seconda della configurazione del server:

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

404 ........................... – Pacerier

+0

Aggiornato il collegamento –

0

Esempio Come utilizzare HttpRequest per inviare i dati e ricevere la risposta:

<?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

ci sono 2 esempio metodo GET e POST Metodo

GET esempio:

<?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; 
} 
?> 

messaggio di esempio

<?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

L'OP ha richiesto 'HTTPS' – jimasun

Problemi correlati