परिचय
https:// और https:// ट्रांसपोर्ट के लिए कॉन्टेक्स्ट विकल्पों की सूची नीचे दी गई है:
| विकल्प | विवरण |
|---|---|
| method | रिमोट सर्वर द्वारा समर्थित HTTP मेथड। डिफ़ॉल्ट GET। |
| header | रिक्वेस्ट के दौरान भेजे जाने वाले अतिरिक्त हेडर। |
| user_agent | User-Agent: हेडर के साथ भेजा जाने वाला मान। डिफ़ॉल्ट रूप से php.ini में user_agent सेटिंग उपयोग की जाती है। |
| content | हेडर के बाद भेजा जाने वाला अतिरिक्त डेटा। आमतौर पर POST या PUT रिक्वेस्ट के साथ उपयोग किया जाता है। |
| proxy | प्रॉक्सी सर्वर के पते को निर्दिष्ट करने वाला URI। |
| request_fulluri boolean | TRUE पर सेट होने पर, रिक्वेस्ट बनाते समय पूरा URI उपयोग किया जाएगा। डिफ़ॉल्ट FALSE। |
| follow_location | Location हेडर रीडायरेक्ट का पालन करें। 0 पर सेट करके अक्षम करें। डिफ़ॉल्ट 1। |
| max_redirects | पालन करने के लिए अधिकतम रीडायरेक्ट की संख्या। |
| protocol_version | HTTP प्रोटोकॉल वर्जन। डिफ़ॉल्ट 1.0। |
| timeout | सेकंड में रीड टाइमआउट, फ्लोट द्वारा निर्दिष्ट (उदाहरण: 10.5)। |
| ignore_errors | विफलता स्टेटस कोड पर भी कंटेंट प्राप्त करें। डिफ़ॉल्ट FALSE। |
निम्न उदाहरण https:// URL से हेडर्स और कंटेंट प्राप्त करता है:
उदाहरण
<?php
$url = "https://localhost/testscript.php";
$opts = array(
'http' => array(
'method' => 'GET',
'max_redirects' => '0',
'ignore_errors' => '1'
)
);
$context = stream_context_create($opts);
$stream = fopen($url, 'r', false, $context);
var_dump(stream_get_meta_data($stream));
?>
आउटपुट
array(10) {
["timed_out"]=> bool(false)
["blocked"]=> bool(true)
["eof"]=> bool(false)
["wrapper_data"]=> array(7) {
[0]=> string(15) "HTTP/1.1 200 OK"
[1]=> string(35) "Date: Thu, 17 Sep 2020 07:04:47 GMT"
[2]=> string(55) "Server: Apache/2.4.41 (Win64) OpenSSL/1.0.2s PHP/7.1.32"
[3]=> string(24) "X-Powered-By: PHP/7.1.32"
[4]=> string(17) "Content-Length: 0"
[5]=> string(17) "Connection: close"
[6]=> string(38) "Content-Type: text/html; charset=UTF-8"
}
["wrapper_type"]=> string(4) "http"
["stream_type"]=> string(14) "tcp_socket/ssl"
["mode"]=> string(1) "r"
["unread_bytes"]=> int(0)
["seekable"]=> bool(false)
["uri"]=> string(31) "https://localhost/testscript.php"
}
उपयोग: कस्टम हेडर, प्रॉक्सी, टाइमआउट, रीडायरेक्ट नियंत्रण के साथ HTTP रिक्वेस्ट अनुकूलित करने के लिए।