当前位置: 首页>>代码示例>>Python>>正文


Python pycurl.POST属性代码示例

本文整理汇总了Python中pycurl.POST属性的典型用法代码示例。如果您正苦于以下问题:Python pycurl.POST属性的具体用法?Python pycurl.POST怎么用?Python pycurl.POST使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pycurl的用法示例。


在下文中一共展示了pycurl.POST属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_page

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def get_page(url, data=None, logfile=None, cookiefile=None, retries=1, filename=None, **kwargs):
    """Simple page fetcher using the HTTPRequest.

    Args::

        url         : A string or UniversalResourceLocator object.
        data        : Dictionary of POST data (of not provided a GET is performed).
        logfile     : A file-like object to write the transaction to.
        cookiefile  : Update cookies in this file, if provided.
        retries     : Number of times to retry the transaction.
        filename    : Name of file to write target object directly to.
                      The doc and body attributes will not be available in the
                      response if this is given.

    Extra keyword arguments are passed to the HTTPRequest object.

    Returns::
        an HTTPResponse object.
    """
    request = HTTPRequest(url, data, **kwargs)
    return request.perform(logfile, cookiefile, retries, filename) 
开发者ID:kdart,项目名称:pycopia,代码行数:23,代码来源:client.py

示例2: get_URLencoded_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def get_URLencoded_poster(self):
        """Initialze a Curl object for a single POST request.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        data = urlparse.urlencode(self._data, True)
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.POST, 1)
        c.setopt(pycurl.POSTFIELDS, data)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        headers = self._headers[:]
        headers.append(httputils.ContentType("application/x-www-form-urlencoded"))
        headers.append(httputils.ContentLength(str(len(data))))
        c.setopt(c.HTTPHEADER, map(str, headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:21,代码来源:client.py

示例3: get_form_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def get_form_poster(self):
        """Initialze a Curl object for a single POST request.

        This sends a multipart/form-data, which allows you to upload files.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        data = self._data.items()
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.HTTPPOST, data)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:18,代码来源:client.py

示例4: get_raw_poster

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def get_raw_poster(self):
        """Initialze a Curl object for a single POST request.

        This sends whatever data you give it, without specifying the content
        type.

        Returns a tuple of initialized Curl and HTTPResponse objects.
        """
        ld = len(self._data)
        c = pycurl.Curl()
        resp = HTTPResponse(self._encoding)
        c.setopt(c.URL, str(self._url))
        c.setopt(pycurl.POST, 1)
        c.setopt(c.READFUNCTION, DataWrapper(self._data).read)
        c.setopt(c.POSTFIELDSIZE, ld)
        c.setopt(c.WRITEFUNCTION, resp._body_callback)
        c.setopt(c.HEADERFUNCTION, resp._header_callback)
        headers = self._headers[:]
        headers.append(httputils.ContentType("")) # removes libcurl internal header
        headers.append(httputils.ContentLength(str(ld)))
        c.setopt(c.HTTPHEADER, map(str, headers))
        self._set_common(c)
        return c, resp 
开发者ID:kdart,项目名称:pycopia,代码行数:25,代码来源:client.py

示例5: post_URL

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def post_URL(self, obj, data, logfile=None, **kwargs):
        """Perform a POST method.
        """
        obj_t = type(obj)
        if issubclass(obj_t,    (str, urlparse.UniversalResourceLocator)):
            r = HTTPRequest(obj, **kwargs)
            r.method = "POST"
            r.data = data
            resp = r.perform(logfile)
            if resp.error:
                return [], [resp] # consistent API
            else:
                return [resp], []
        elif issubclass(obj_t, HTTPRequest):
            obj.method = "POST"
            obj.data = data
            resp = obj.perform(logfile)
            return [resp], []
        else: # assumed to be iterables
            for url, rd in itertools.izip(iter(obj), iter(data)):
                r = HTTPRequest(str(url), **kwargs)
                r.method = "POST"
                r.data = rd
                self._requests.append(r)
                return self.perform(logfile) 
开发者ID:kdart,项目名称:pycopia,代码行数:27,代码来源:client.py

示例6: __init__

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def __init__(self, fd):
    self.rfile = fd
    self.error = None
    self.body = None

    command, path, version = B(self.rfile.readline()).split()
    self.raw_requestline = b('%s %s %s' % (command, path, 'HTTP/1.1' if version.startswith('HTTP/2') else version))

    self.parse_request()
    self.request_version = version

    if self.command == 'POST':
      self.body = B(self.rfile.read(-1)).rstrip('\r\n')

      if 'Content-Length' in self.headers:
        del self.headers['Content-Length'] 
开发者ID:lanjelot,项目名称:patator,代码行数:18,代码来源:patator.py

示例7: perform_fp

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def perform_fp(fp, method, url, header='', body=''):
    #logger.debug('perform: %s' % url)
    fp.setopt(pycurl.URL, url)

    if method == 'GET':
      fp.setopt(pycurl.HTTPGET, 1)

    elif method == 'POST':
      fp.setopt(pycurl.POST, 1)
      fp.setopt(pycurl.POSTFIELDS, body)

    elif method == 'HEAD':
      fp.setopt(pycurl.NOBODY, 1)

    else:
      fp.setopt(pycurl.CUSTOMREQUEST, method)

    headers = [h.strip('\r') for h in header.split('\n') if h]
    fp.setopt(pycurl.HTTPHEADER, headers)

    fp.perform() 
开发者ID:lanjelot,项目名称:patator,代码行数:23,代码来源:patator.py

示例8: setup_curl_for_post

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def setup_curl_for_post(c, p, data_buf, headers=None, share=None):
    setup_curl_basic(c, p, data_buf, headers, share)
    httpheader = p.get('httpheader', ['Accept: application/json', "Content-type: application/json"])
    if httpheader:
        # c.setopt(pycurl.HEADER, p.get('header', 1))
        c.setopt(pycurl.HTTPHEADER, httpheader)
    post301 = getattr(pycurl, 'POST301', None)
    if post301 is not None:
        # Added in libcurl 7.17.1.
        c.setopt(post301, True)
    c.setopt(pycurl.POST, 1)
    postfields = p.get('postfields')
    if postfields:
        postfields = json.dumps(postfields, indent=2, ensure_ascii=False)
        c.setopt(pycurl.POSTFIELDS, postfields)
    return c 
开发者ID:pingf,项目名称:falsy,代码行数:18,代码来源:utils.py

示例9: test_post

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def test_post(self):
        curl = CurlStub(b"result")
        result = fetch("http://example.com", post=True, curl=curl)
        self.assertEqual(result, b"result")
        self.assertEqual(curl.options,
                         {pycurl.URL: b"http://example.com",
                          pycurl.FOLLOWLOCATION: 1,
                          pycurl.MAXREDIRS: 5,
                          pycurl.CONNECTTIMEOUT: 30,
                          pycurl.LOW_SPEED_LIMIT: 1,
                          pycurl.LOW_SPEED_TIME: 600,
                          pycurl.NOSIGNAL: 1,
                          pycurl.WRITEFUNCTION: Any(),
                          pycurl.POST: True,
                          pycurl.DNS_CACHE_TIMEOUT: 0,
                          pycurl.ENCODING: b"gzip,deflate"}) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:18,代码来源:test_fetch.py

示例10: test_post_data

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def test_post_data(self):
        curl = CurlStub(b"result")
        result = fetch("http://example.com", post=True, data="data", curl=curl)
        self.assertEqual(result, b"result")
        self.assertEqual(curl.options[pycurl.READFUNCTION](), b"data")
        self.assertEqual(curl.options,
                         {pycurl.URL: b"http://example.com",
                          pycurl.FOLLOWLOCATION: 1,
                          pycurl.MAXREDIRS: 5,
                          pycurl.CONNECTTIMEOUT: 30,
                          pycurl.LOW_SPEED_LIMIT: 1,
                          pycurl.LOW_SPEED_TIME: 600,
                          pycurl.NOSIGNAL: 1,
                          pycurl.WRITEFUNCTION: Any(),
                          pycurl.POST: True,
                          pycurl.POSTFIELDSIZE: 4,
                          pycurl.READFUNCTION: Any(),
                          pycurl.DNS_CACHE_TIMEOUT: 0,
                          pycurl.ENCODING: b"gzip,deflate"}) 
开发者ID:CanonicalLtd,项目名称:landscape-client,代码行数:21,代码来源:test_fetch.py

示例11: setPostData

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def setPostData(self, pd, boundary=None):
        self._non_parsed_post = pd
        self._variablesPOST = VariablesSet()

        try:
            if self.ContentType == "multipart/form-data":
                self._variablesPOST.parseMultipart(pd, boundary)
            elif self.ContentType == 'application/json':
                self._variablesPOST.parse_json_encoded(pd)
            else:
                self._variablesPOST.parseUrlEncoded(pd)
        except Exception:
            try:
                self._variablesPOST.parseUrlEncoded(pd)
            except Exception:
                print("Warning: POST parameters not parsed")
                pass

############################################################################ 
开发者ID:xmendez,项目名称:wfuzz,代码行数:21,代码来源:Request.py

示例12: send_REST_request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def send_REST_request(ip, port, payload):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/server/restart" %(
            ip, port)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        conn.setopt(pycurl.POST, 1)
        conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None
# end def send_REST_request 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:19,代码来源:smgr_restart_server.py

示例13: send_REST_request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def send_REST_request(ip, port, payload):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/server/reimage" %(
            ip, port)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        conn.setopt(pycurl.POST, 1)
        conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:18,代码来源:smgr_reimage_server.py

示例14: send_REST_request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def send_REST_request(ip, port, payload):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/server/provision" %(
            ip, port)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.HTTPHEADER, headers)
        conn.setopt(pycurl.POST, 1)
        conn.setopt(pycurl.POSTFIELDS, '%s'%json.dumps(payload))
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:18,代码来源:smgr_provision_server.py

示例15: send_REST_request

# 需要导入模块: import pycurl [as 别名]
# 或者: from pycurl import POST [as 别名]
def send_REST_request(ip, port, payload, file_name,
                      kickstart='', kickseed=''):
    try:
        response = StringIO()
        headers = ["Content-Type:application/json"]
        url = "http://%s:%s/image/upload" %(
            ip, port)
        conn = pycurl.Curl()
        conn.setopt(pycurl.URL, url)
        conn.setopt(pycurl.POST, 1)
        payload["file"] = (pycurl.FORM_FILE, file_name)
        if kickstart:
            payload["kickstart"] = (pycurl.FORM_FILE, kickstart)
        if kickseed:
            payload["kickseed"] = (pycurl.FORM_FILE, kickseed)
        conn.setopt(pycurl.HTTPPOST, payload.items())
        conn.setopt(pycurl.CUSTOMREQUEST, "PUT")
        conn.setopt(pycurl.WRITEFUNCTION, response.write)
        conn.perform()
        return response.getvalue()
    except:
        return None 
开发者ID:Juniper,项目名称:contrail-server-manager,代码行数:24,代码来源:smgr_upload_image.py


注:本文中的pycurl.POST属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。