HTTP request Terminator under httplib2-python

Source: Internet
Author: User

Httplib2 features: http://code.google.com/p/httplib2/

Httplib2 instance page: http://code.google.com/p/httplib2/w/list

Httplib2 problem submission: http://code.google.com/p/httplib2/issues/list

Well, I think the official examples are quite comprehensive. I 'd like to paste them here.

Simple Retrieval
 
Import httplib2h = httplib2.http (". cache") resp, content = H. Request ("http://example.org/", "get ")

Authentication
 
Import httplib2h = httplib2.http (". cache ") H. add_credentials ('name', 'Password') resp, content = H. request ("https://example.org/chap/2", # SSL + Base authentication "put", body = "this is text", headers = {'content-type': 'text/plain '})
Cache-control
Import httplib2h = httplib2.http (". cache ") resp, content = H. request ("http://bitworking.org/") # The request is cached and will be used next time instead of sending new requests. The cache takes effect at a web configuration... resp, content = H. request ("http://bitworking.org/", headers = {'cache-control': 'no-cache'}) # set no cache, this time will not cache, instead, send a new request directly.
Forms
 
>>> From httplib2 import HTTP >>> from urllib import urlencode >>> H = http () >>> DATA = dict (name = "Joe ", comment = "A test comment") >>> resp, content = H. request ("http://bitworking.org/news/223/Meet-Ares", "Post", urlencode (data) >>> resp {'status': '20170101', 'transfer-encoding': 'chunked ', 'vary ': 'Accept-encoding, user-agent', 'server': 'apache', 'connection': 'close', 'date': 'tue, 31 Jul 2007 15:29:52 gmt', 'content-type': 'text/html '}
Cookies
#! /Usr/bin/ENV pythonimport urllibimport httplib2http = httplib2.http () url = 'HTTP: // www.example.com/login' body = {'username': 'foo', 'Password ': 'bar'} headers = {'content-type': 'application/X-WWW-form-urlencoded'} response, content = http. request (URL, 'post', headers = headers, body = urllib. urlencode (body) headers = {'cookies': Response ['set-cookies'] ### set the obtained cookie to the request header, for the next request, use url = 'HTTP: // www.example.com/home' response, content = http. request (URL, 'get', headers = headers) # the user name and password are not required for this request.
Proxies
 
Import httplib2import socks # third-party module httplib2.debuglevel = 4 H = httplib2.http (proxy_info = httplib2.proxyinfo (socks. proxy_type_http, 'localhost', 8000) R, c = H. request ("http://bitworking.org/news ")

========================================================== ========================================================== ======

The following is my attempt to implement the module functions:

HTTP Object Construction Method: _ init _ (self, cache = none, timeout = none, proxy_info = none, ca_certs = none, disable_ssl_certificate_validation = false) the value of proxy_info is a proxyinfo instance. | 'cache': the location where the cache is stored. It is either a string or an object supporting the File Cache interface. | Timeout: timeout time, by default, the python value for socket connection timeout is obtained. | ca_certs: A file path used for SSL server authentication that contains the master CA authentication, the httplib2 bound certificate is used by default. | disable_ssl_certificate_validation: determines whether SSL authentication is performed. | add_certificate (self, key, CER T, domain) | add an SSL authentication key and file | add_credentials (self, name, password, domain = '') | Add a user name and password information | clear_credentials (Self) | delete all user names and password information. It seems that multiple user names and passwords can still be stored. HTTP. request (self, Uri, method = 'get', body = none, headers = none, redirections = 5, connection_type = none) Description: execute a single HTTP request URI: A Resource Locator string starting with 'http' or 'https' must be an absolute address method: supports all HTTP request methods. For example, get, post, delete, Etc .. body: the requested attachment data, which goes through urllib. urlencode-encoded string headers: request header information. A dictionary object redirections: the maximum number of automatic consecutive redirects. The default value is 5. Returned: (response, content) tuples. response is an httplib2.response object, content is the string httplib2.response that contains the source code of the webpage. It is actually a dictionary containing all header information, because it is an integrated self-dictionary object.

In addition, The httplib2 module itself has other objects or attributes, which can be viewed through print Dir (httplib2).

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.