Zend Framework の紹介

 Learning Zend Framework


 Zend Framework リファレンス

  • 第36章 Zend_Gdata
  • 第37章 Zend_Http
  • 第38章 Zend_InfoCard
  • 第39章 Zend_Json
  • 第40章 Zend_Layout
  • 第41章 Zend_Ldap
  • 第42章 Zend_Loader
  • 第43章 Zend_Locale
  • 第44章 Zend_Log
  • 第45章 Zend_Mail
  • 第46章 Zend_Markup
  • 第47章 Zend_Measure
  • 第48章 Zend_Memory
  • 第49章 Zend_Mime
  • 第50章 Zend_Navigation
  • 第51章 Zend_Oauth
  • 第52章 Zend_OpenId
  • 第53章 Zend_Paginator
  • 第54章 Zend_Pdf
  • 第55章 Zend_ProgressBar
  • 第56章 Zend_Queue
  • 第57章 Zend_Reflection
  • 第58章 Zend_Registry
  • 第59章 Zend_Rest

  • 第60章 Zend_Search_Lucene
  • 第61章 Zend_Serializer
  • 第62章 Zend_Server
  • 第63章 Zend_Service
  • 第64章 Zend_Session
  • 第65章 Zend_Soap
  • 第66章 Zend_Tag
  • 第67章 Zend_Test
  • 第68章 Zend_Text
  • 第69章 Zend_TimeSync
  • 第70章 Zend_Tool
  • 第71章 Zend_Tool_Framework
  • 第72章 Zend_Tool_Project
  • 第73章 Zend_Translate
  • 第74章 Zend_Uri
  • 第75章 Zend_Validate
  • 第76章 Zend_Version
  • 第77章 Zend_View
  • 第78章 Zend_Wildfire
  • 第79章 Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Translation 70.6% Update 2010-11-28 - Revision 23415

    第37章 Zend_Http


    37.1. Introduction
    37.1.1. Using Zend_Http_Client
    37.1.2. Configuration Parameters
    37.1.3. Performing Basic HTTP Requests
    37.1.4. Adding GET and POST parameters
    37.1.5. Accessing Last Request and Response
    37.2. Zend_Http_Client - 高度な使用法
    37.2.1. HTTP リダイレクト
    37.2.2. クッキーの追加および持続的なクッキーの使用
    37.2.3. 独自のリクエストヘッダの設定
    37.2.4. ファイルのアップロード
    37.2.5. 生の POST データの送信
    37.2.6. HTTP 認証
    37.2.7. 同一クライアントでの複数リクエストの送信
    37.2.8. データ・ストリーミング
    37.3. Zend_Http_Client - Connection Adapters
    37.3.1. Overview
    37.3.2. The Socket Adapter Customizing and accessing the Socket adapter stream context
    37.3.3. The Proxy Adapter
    37.3.4. The cURL Adapter
    37.3.5. The Test Adapter
    37.3.6. Creating your own connection adapters
    37.4. Zend_Http_Cookie and Zend_Http_CookieJar
    37.4.1. Introduction
    37.4.2. Instantiating Zend_Http_Cookie Objects
    37.4.3. Zend_Http_Cookie getter methods
    37.4.4. Zend_Http_Cookie: Matching against a scenario
    37.4.5. The Zend_Http_CookieJar Class: Instantiation
    37.4.6. Adding Cookies to a Zend_Http_CookieJar object
    37.4.7. Retrieving Cookies From a Zend_Http_CookieJar object
    37.5. Zend_Http_Response
    37.5.1. 導入
    37.5.2. 真偽チェック用のメソッド
    37.5.3. アクセス用メソッド群
    37.5.4. 静的 HTTP レスポンスパーサ
    37.6. Zend_Http_UserAgent
    37.6.1. Overview
    37.6.2. Quick Start
    37.6.3. Configuration Options
    37.6.4. Available Methods
    37.6.5. Examples
    37.7. The UserAgent Device Interface
    37.7.1. Overview
    37.7.2. Quick Start
    37.7.3. Configuration Options
    37.7.4. Available Methods
    37.7.5. Examples
    37.8. The UserAgent Features Adapter
    37.8.1. Overview
    37.8.2. Quick Start
    37.8.3. Configuration Options
    37.8.4. Available Methods
    37.9. The WURFL UserAgent Features Adapter
    37.9.1. Overview
    37.9.2. Quick Start
    37.9.3. Configuration Options
    37.9.4. Available Methods
    37.10. The DeviceAtlas UserAgent Features Adapter
    37.10.1. Overview
    37.10.2. Quick Start
    37.10.3. Configuration Options
    37.10.4. Available Methods
    37.11. The TeraWurfl UserAgent Features Adapter
    37.11.1. Overview
    37.11.2. Quick Start
    37.11.3. Configuration Options
    37.11.4. Available Methods
    37.12. The UserAgent Storage Interface
    37.12.1. Overview
    37.12.2. Quick Start
    37.12.3. Configuration Options
    37.12.4. Available Methods
    37.13. The Session UserAgent Storage Adapter
    37.13.1. Overview
    37.13.2. Quick Start
    37.13.3. Configuration Options
    37.13.4. Available Methods

    37.1. Introduction

    Zend_Http_Client provides an easy interface for preforming Hyper-Text Transfer Protocol (HTTP) requests. Zend_Http_Client supports most simple features expected from an HTTP client, as well as some more complex features such as HTTP authentication and file uploads. Successful requests (and most unsuccessful ones too) return a Zend_Http_Response object, which provides access to the response's headers and body (see this section).

    37.1.1. Using Zend_Http_Client

    The class constructor optionally accepts a URL as its first parameter (can be either a string or a Zend_Uri_Http object), and an array or Zend_Config object containing configuration options. Both can be left out, and set later using the setUri() and setConfig() methods.

    例 37.1. Instantiating a Zend_Http_Client Object

    $client = new Zend_Http_Client('http://example.org', array(
    'maxredirects' => 0,
    'timeout'      => 30));

    // This is actually exactly the same:
    $client = new Zend_Http_Client();
    'maxredirects' => 0,
    'timeout'      => 30));

    // You can also use a Zend_Config object to set the client's configuration
    $config = new Zend_Config_Ini('httpclient.ini''secure');

    [注意] 注意

    Zend_Http_Client uses Zend_Uri_Http to validate URLs. This means that some special characters like the pipe symbol ('|') or the caret symbol ('^') will not be accepted in the URL by default. This can be modified by setting the 'allow_unwise' option of Zend_Uri to 'TRUE'. See this section for more information.

    37.1.2. Configuration Parameters

    The constructor and setConfig() method accept an associative array of configuration parameters, or a Zend_Config object. Setting these parameters is optional, as they all have default values.

    表 37.1. Zend_Http_Client configuration parameters

    Parameter Description Expected Values Default Value
    maxredirects Maximum number of redirections to follow (0 = none) integer 5
    strict Whether perform validation on header names. When set to FALSE, validation functions will be skipped. Usually this should not be changed boolean TRUE
    strictredirects Whether to strictly follow the RFC when redirecting (see this section) boolean FALSE
    useragent User agent identifier string (sent in request headers) string 'Zend_Http_Client'
    timeout Connection timeout (seconds) integer 10
    httpversion HTTP protocol version (usually '1.1' or '1.0') string '1.1'
    adapter Connection adapter class to use (see this section) mixed 'Zend_Http_Client_Adapter_Socket'
    keepalive Whether to enable keep-alive connections with the server. Useful and might improve performance if several consecutive requests to the same server are performed. boolean FALSE
    storeresponse Whether to store last response for later retrieval with getLastResponse(). If set to FALSE getLastResponse() will return NULL. boolean TRUE
    encodecookies Whether to pass the cookie value through urlencode/urldecode. Enabling this breaks support with some web servers. Disabling this limits the range of values the cookies can contain. boolean TRUE

    37.1.3. Performing Basic HTTP Requests

    Performing simple HTTP requests is very easily done using the request() method, and rarely needs more than three lines of code:

    例 37.2. Performing a Simple GET Request

    $client = new Zend_Http_Client('http://example.org');
    $response $client->request();

    The request() method takes one optional parameter - the request method. This can be either GET, POST, PUT, HEAD, DELETE, TRACE, OPTIONS or CONNECT as defined by the HTTP protocol [6]. For convenience, these are all defined as class constants: Zend_Http_Client::GET, Zend_Http_Client::POST and so on.

    If no method is specified, the method set by the last setMethod() call is used. If setMethod() was never called, the default request method is GET (see the above example).

    例 37.3. Using Request Methods Other Than GET

    // Preforming a POST request
    $response $client->request('POST');

    // Yet another way of preforming a POST request
    $response $client->request();

    37.1.4. Adding GET and POST parameters

    Adding GET parameters to an HTTP request is quite simple, and can be done either by specifying them as part of the URL, or by using the setParameterGet() method. This method takes the GET parameter's name as its first parameter, and the GET parameter's value as its second parameter. For convenience, the setParameterGet() method can also accept a single associative array of name => value GET variables - which may be more comfortable when several GET parameters need to be set.

    例 37.4. Setting GET Parameters

    // Setting a get parameter using the setParameterGet method

    // This is equivalent to setting such URL:

    // Adding several parameters with one call
    'first_name'  => 'Bender',
    'middle_name' => 'Bending'
    => 'Mexico',

    While GET parameters can be sent with every request method, POST parameters are only sent in the body of POST requests. Adding POST parameters to a request is very similar to adding GET parameters, and can be done with the setParameterPost() method, which is similar to the setParameterGet() method in structure.

    例 37.5. Setting POST Parameters

    // Setting a POST parameter

    // Setting several POST parameters, one of them with several values
    'language'  => 'es',
    'country'   => 'ar',
    'selection' => array(453280)

    Note that when sending POST requests, you can set both GET and POST parameters. On the other hand, while setting POST parameters for a non-POST request will not trigger and error, it is useless. Unless the request is a POST request, POST parameters are simply ignored.

    37.1.5. Accessing Last Request and Response

    Zend_Http_Client provides methods of accessing the last request sent and last response received by the client object. Zend_Http_Client->getLastRequest() takes no parameters and returns the last HTTP request sent by the client as a string. Similarly, Zend_Http_Client->getLastResponse() returns the last HTTP response received by the client as a Zend_Http_Response object.

    digg delicious meneame google twitter technorati facebook