當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。