Python HTTP客户端请求– GET,POST

Python HTTP module defines the classes which provide the client-side of the HTTP and HTTPS protocols. In most of the programs, the HTTP module is not directly used and is clubbed with the urllib module to handle URL connections and interaction with HTTP requests. Today we will learn how to use a Python HTTP client to fire HTTP request and then parse response status and get response body data.

Python HTTP模块定义了提供HTTP和HTTPS协议客户端的类。 在大多数程序中,HTTP模块不是直接使用,而是与urllib模块组合在一起以处理URL连接以及与HTTP请求的交互。 今天,我们将学习如何使用Python HTTP客户端来触发HTTP请求,然后解析响应状态并获取响应主体数据。

Python HTTP客户端 (Python HTTP Client)

In this post on python HTTP module, we will try attempting making connections and making HTTP requests like GET, POST and PUT. Let’s get started.

在python HTTP模块的这篇文章中,我们将尝试尝试建立连接并发出GET,POST和PUT之类的HTTP请求。 让我们开始吧。

建立HTTP连接 (Making HTTP Connections)

We will start with the simplest thing HTTP module can do. We can easily make HTTP connections using this module. Here is a sample program:

我们将从HTTP模块可以做的最简单的事情开始。 我们可以使用此模块轻松建立HTTP连接。 这是一个示例程序:

import http.client

connection = http.client.HTTPConnection('www.python.org', 80, timeout=10)
print(connection)

Let’s see the output for this program:

python http connection

In this script, we connected to the URL on Port 80 with a specific timeout.

让我们看一下该程序的输出:

在此脚本中,我们以特定的超时时间连接到端口80上的URL。

Python HTTP GET (Python HTTP GET

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值