/ / गाउट में कुकीज़ कैसे सेट करें? - php, कूकीज, सेटकुकी, गाउट

Goutte में कुकीज़ कैसे सेट करें? - php, कूकीज, सेटकुकी, गाउट

मैं "Goutte में कुकीज़ सेट करने का तरीका पता लगा सकता हूं। मैं निम्नलिखित कोड की कोशिश कर रहा हूं:

$client->setHeader("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.111 Safari/537.36");
$client->getCookieJar()->set("SRCHUID");

मैं इस नाम के साथ कुकी की एक छवि संलग्न कर रहा हूं। मैं इस कुकी को कैसे सेट कर सकता हूं?

यहां छवि विवरण दर्ज करें

उत्तर:

जवाब के लिए 2 № 1

गाउट 6 के साथ गाउट

use GuzzleHttpCookie;

$cookieJar = new GuzzleHttpCookieCookieJar(true);

$cookieJar->setCookie(new GuzzleHttpCookieSetCookie([
"Domain"  => "www.domain.com",
"Name"    => $name,
"Value"   => $value,
"Discard" => true
]));

$client = new Client();
$guzzleclient = new GuzzleHttpClient([
"timeout" => 900,
"verify" => false,
"cookies" => $cookieJar
]);
$client->setClient($guzzleclient);

return $client; //or do your normal client request here e.g $client->request("GET", $url);

उत्तर № 2 के लिए 1

मेरे लिए गज़लेकिएंट डिड "टी वर्क का उपयोग करते हुए। मैंने कुकीज को GetCookieJar द्वारा लौटाया। प्रारंभिक प्रश्न में केवल एक ही गलती मुझे दिखाई देती है कि आप केवल एक स्ट्रिंग मान प्रदान करके कुकी सेट करने का प्रयास करते हैं। काम करने के लिए सेट विधि को कुकी इंस्टेंस की आवश्यकता होती है। हस्ताक्षर हैं:

/**
* Sets a cookie.
*
* @param Cookie $cookie A Cookie instance
*/
public function set(Cookie $cookie)

उदाहरण:

$this->client->getCookieJar()->set(new Cookie($name, $value, null, null, $domain));

ध्यान रखें कि कुकी मान को एन्कोड न करें या एन्कोडेडवैल्यू को सही सेट करें

कुकी __construct के हस्ताक्षर:

/**
* Sets a cookie.
*
* @param string $name         The cookie name
* @param string $value        The value of the cookie
* @param string $expires      The time the cookie expires
* @param string $path         The path on the server in which the cookie will be available on
* @param string $domain       The domain that the cookie is available
* @param bool   $secure       Indicates that the cookie should only be transmitted over a secure HTTPS connection from the client
* @param bool   $httponly     The cookie httponly flag
* @param bool   $encodedValue Whether the value is encoded or not
*/
public function __construct($name, $value, $expires = null, $path = null, $domain = "", $secure = false, $httponly = true, $encodedValue = false)