2010-10-06 10 views
10

मैं सर्वर से PHP के माध्यम से HTTPS अनुरोध करना चाहता हूं और प्रतिक्रिया प्राप्त करना चाहता हूं। इस गहरे लाल रंग का कोड के समानPHP के माध्यम से एक HTTPS अनुरोध करें और प्रतिक्रिया प्राप्त करें

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

    http.use_ssl = true 

    path = "uri" 

    resp, data = http.get(path, nil) 

धन्यवाद

उत्तर

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

+0

लिंक सही था! आप कम से कम curl_setopt ($ ch, CURLOPT_SSL_VERIFYPEER, false) रखने के लिए अपना उत्तर अपडेट कर सकते हैं; लाइन – rsc

1

Zend FrameworkZend_Http_Client कहा जाता है एक अच्छा घटक है जो लेन-देन के इस प्रकार के लिए एकदम सही है।

हुड के तहत यह अनुरोध करने के लिए curl का उपयोग करता है, लेकिन आप पाएंगे कि Zend_Http_Client के साथ काम करने के लिए एक बहुत अच्छा इंटरफ़ेस है और कॉन्फ़िगर करना आसान है जब आप कस्टम हेडर जोड़ना चाहते हैं या प्रतिक्रियाओं के साथ काम करना चाहते हैं।

सब आप क्या करना चाहते है, तो कम से कम काम के साथ पेज सामग्री को पुनः प्राप्त है, तो आप अपने सर्वर का विन्यास पर निर्भर करता है, निम्नलिखित ऐसा करने में सक्षम हो सकता है:

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

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

+0

लिंक –

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 पद्धति और बाद विधि

उदाहरण प्राप्त कर रहे हैं:

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

अपडेट किया गया ओपी ने 'HTTPS' के लिए कहा – jimasun

संबंधित मुद्दे