• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python vertx.create_http_client函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中vertx.create_http_client函数的典型用法代码示例。如果您正苦于以下问题:Python create_http_client函数的具体用法?Python create_http_client怎么用?Python create_http_client使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

示例1: request

def request(method, url, response_handler, params, headers):
    tgt = urlparse(url)
    ssl = (tgt.scheme == "https")
    port = (80 if not ssl else 443)
    client = vertx.create_http_client(ssl=ssl, port=port, host=tgt.hostname)

    params_encoded = []
    for key in sorted(params.iterkeys()):
        params_encoded.append(quote(key) + "=" + quote("%s" % params[key]))

    query_str = '&'.join(params_encoded)

    if method == 'GET':
        req = client.get(tgt.path +'?'+ query_str, response_handler)
    else:
        req = client.post(tgt.path, response_handler)
        if len(query_str) > 0:
            req.put_header('Content-Length', str(len(query_str)))
            req.put_header('Content-Type', "application/x-www-form-urlencoded")
            req.write_str(query_str)
    for key, val in headers.items():
        req.put_header(key, val)
    req.put_header('User-Agent', "stt")
    req.end()
开发者ID:stt,项目名称:vertx-trans,代码行数:24,代码来源:utils.py


示例2: listen_handler

 def listen_handler(err, server):
     VertxAssert.assertNull(err)
     # The server is listening so send an HTTP request
     vertx.create_http_client().set_port(8181).get_now("/", resp_handler)
开发者ID:normanmaurer,项目名称:mod-smtpserver,代码行数:4,代码来源:basic_integration_test.py


示例3: TestUtils

# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import vertx
from test_utils import TestUtils
from core.http import RouteMatcher

tu = TestUtils()

server = vertx.create_http_server()
rm = RouteMatcher()
server.request_handler(rm)
server.listen(8080)

client = vertx.create_http_client()
client.port = 8080;

class RouteMatcherTest(object):
    def __init__(self):
        self.params = { "name" : "foo", "version" : "v0.1"}
        self.re_params = { "param0" : "foo", "param1" : "v0.1"}
        self.regex = "\\/([^\\/]+)\\/([^\\/]+)"

    def test_get_with_pattern(self): 
        route('get', False, "/:name/:version", self.params, "/foo/v0.1")


    def test_get_with_regex(self): 
        route('get', True, self.regex, self.re_params, "/foo/v0.1")
开发者ID:emangchi,项目名称:vert.x,代码行数:30,代码来源:test_client.py


示例4: request_handler

#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import vertx

client = vertx.create_http_client(port=8282, host="localhost")
server = vertx.create_http_server()

@server.request_handler
def request_handler(req):
  print "Proxying request: %s"% req.uri
  def response_handler(c_res):
    print "Proxying response: %s"% c_res.status_code
    req.response.chunked = True
    req.response.status_code = c_res.status_code
    for header in c_res.headers.keys():
      req.response.put_header(header, c_res.headers[header])
    def data_handler(data):
      print "Proxying response body: %s"% data
      req.response.write_buffer(data)
    c_res.data_handler(data_handler)
开发者ID:EunsanKo,项目名称:vert.x,代码行数:31,代码来源:proxy_server.py


示例5: request

    def request(self, response_handler, method="GET", path="/", query=None):
        """
        Make an oauth signed request
        """

        if path[0] != "/":
            path = "/" + path

        # Data required for a sgned request
        auth_params = {
            "oauth_consumer_key": self.consumer_key,
            "oauth_nonce": "".join([str(random.randint(0, 9)) for i in range(32)])
            if self.nonce is None
            else self.nonce,
            "oauth_signature_method": "HMAC-SHA1",
            "oauth_timestamp": int(time.time()) if self.timestamp is None else self.timestamp,
            "oauth_token": self.oauth_token,
            "oauth_version": "1.0",
        }

        # Build signature
        sig_data = method + "&" + self.quote(self.api_endpoint.scheme + "://" + self.api_endpoint.hostname + path)
        params_encoded = []
        for key in sorted(auth_params.iterkeys()):
            params_encoded.append(self.quote(key) + "=" + self.quote("%s" % auth_params[key]))
        if query is not None:
            for key in sorted(query.iterkeys()):
                params_encoded.append(self.quote(key) + "=" + self.quote("%s" % query[key]))
        sig_data = sig_data + "&" + self.quote("&".join(sorted(params_encoded)))
        signing_key = self.quote(self.consumer_secret) + "&" + self.quote(self.oauth_token_secret)
        hashed = hmac.new(signing_key, sig_data, sha1)
        signature = binascii.b2a_base64(hashed.digest())[:-1]
        auth_params["oauth_signature"] = signature

        # Build oauth header
        auth_params_encoded = []
        for key in sorted(auth_params.iterkeys()):
            auth_params_encoded.append('%s="%s"' % (self.quote(key), self.quote("%s" % auth_params[key])))
        auth = "OAuth " + ", ".join(auth_params_encoded)

        # Build request
        query_params = []
        query_str = ""
        if query is not None:
            for key in query:
                query_params.append("%s=%s" % (self.quote(key), self.quote("%s" % query[key])))
        if len(query_params) > 0:
            query_str = "&".join(query_params)

        client = vertx.create_http_client()
        client.host = self.api_endpoint.hostname
        ssl = True if self.api_endpoint.scheme == "https" else False
        client.ssl = ssl
        if self.api_endpoint.port is None:
            client.port = 80 if not ssl else 443
        else:
            client.port = self.api_endpoint.port

        if self.debug:
            print "Compare this output to twitters OAuth tool"
            print "Signature base string:\n" + sig_data
            print "Authorization header:\nAuthorization: " + auth
            print "cURL command:\ncurl %s '%s://%s%s' --data '%s' --header 'Authorization: %s' --verbose" % (
                "--get" if method == "GET" else "--request '%s'" % method,
                self.api_endpoint.scheme,
                self.api_endpoint.netloc,
                path,
                query_str,
                auth,
            )

        if method == "GET":
            request = client.get(path + ("?" + query_str if len(query_str) > 0 else ""), response_handler)
        else:
            request = client.post(path, response_handler)
            if len(query_str) > 0:
                request.put_header("Content-Length", len(query_str))
                request.put_header("Content-Type", "application/x-www-form-urlencoded")
                request.write_str(query_str)
        request.put_header("Authorization", auth)
        request.end()
开发者ID:Gruenderhub,项目名称:twitter-autocurator,代码行数:81,代码来源:oauth.py


示例6: handle_body

# Copyright 2011 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import vertx

client = vertx.create_http_client(port=4443, host="localhost", ssl=True, trust_all=True)

def handle_body(body):
    print "Got data %s"% body

def handle_response(resp):
    print "Got response %s\n" % resp.status_code
    resp.body_handler(handle_body)

client.get_now("/", handle_response)
开发者ID:Ed42,项目名称:vertx-examples,代码行数:26,代码来源:https_client.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python vertx.create_http_server函数代码示例发布时间:2022-05-26
下一篇:
Python vertica_python.connect函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap