3
認証スクリプトを作成する必要があります。クッキーは保存し、あとで使用して許可なくページにアクセスする必要があります。誰かが私に仕事の例を与えることができますか?Zend_Http_Client cURL認証の例
認証スクリプトを作成する必要があります。クッキーは保存し、あとで使用して許可なくページにアクセスする必要があります。誰かが私に仕事の例を与えることができますか?Zend_Http_Client cURL認証の例
まず、サーバーからCookieを取得するための最初のリクエストを行う必要があります。応答では、サーバーが応答ヘッダーSet-Cookie
に送信するCookieを保存します。あなたがそれらを保管する場所はあなた次第です。私はちょうどセッションにそれらを追加しました。
$uri = 'http://example.com';
$client = new Zend_Http_Client();
$client->setUri($uri);
$client->setAdapter('Zend_Http_Client_Adapter_Curl');
$adapter = $client->getAdapter();
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
/** First Request to get required cookies **/
$response = $client->request();
/** Get response cookie strings and store them (session, db, file, etc) **/
$cookies = (array) $response->getHeader('Set-cookie');
$session = new Zend_Session_Namespace();
$session->storedCookies = $cookies;
クッキーが保存されているので、次のリクエストでリクエストに追加することができます。
/** Start new Zend_Http_Client instance **/
$uri = 'http://example.com';
$client = new Zend_Http_Client();
$client->setUri($uri);
$client->setAdapter('Zend_Http_Client_Adapter_Curl');
$adapter = $client->getAdapter();
/** This setCurlOption is optional **/
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, false);
$session = new Zend_Session_Namespace();
$cookies = $session->storedCookies;
/** Add Stored Cookie strings to Zend_Http_Client instance **/
foreach ($cookies as $cookieStr) {
$client->setCookie(Zend_Http_Cookie::fromString($cookieStr, $uri));
}
/** Perform request using stored cookies **/
$response = $client->request();
ご質問があるか、私はちょうど私に知らせて、何について詳しく説明する必要がある場合。
ありがとうございました。私の求めるもの。 私が知っているように、curlは永続的な接続を保持し、それをキュー内のいくつかの要求に使用できます。これはZendでどのようにすることができますか? – Crusader