#coding=utf-8

import http.client
import urllib.parse

#与服务器建立链接
url = 'code.ali.cn:80'

conn = http.client.HTTPConnection(url).  #python3

conn = httplib.HTTPConnection #python2

#向服务器发送请求
method="POST"
requrl = "http://code.ali.cn/v2/tickets-v2"
headerdata = {
  "Host": "code.ali.cn",
  "Accept-Encoding": "gzip",
  "User-Agent": "Android-Up366-Moblie 4.3.0",
  "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
  "Connection": "Keep-Alive"
}
test_data = urllib.parse.urlencode({
  "username": "ali",
  "password": "fdd13a1557f78824820bf028db0e18d9",
  "ut": "c2dc7b2429847da1e4efcc97ef20d867a8161f2d2646680f53cedb93af07cb49",
})

conn.request(method=method,url=requrl,body=test_data,headers = headerdata)

#获取响应消息体
response = conn.getresponse()
print(response.status,response.reason)
data = response.read()
print(data)

#获取响应头部信息,列表形式
resheader=response.getheaders();
print(resheader)

#取出响应头部的Set-Cookie的值
responsehead = response.getheader('Set-Cookie')
print(responsehead)
conn.close()

#python2和python3加载模块

if re.match('^3\.\d\.\d', sys.version):
from http.client import HTTPConnection
import configparser
import urllib.parse as Urllib
elif re.match('^2\.\d\.\d', sys.version):
from httplib import HTTPConnection
import ConfigParser as configparser
import urllib as Urllib

python3 httpConnection——post请求的更多相关文章

  1. Python3发送post请求,自动记住cookie

    转载自:http://www.cnblogs.com/meitian/p/4607737.html 在做登录的post请求时,需要记住cookie,否则不能访问登录后的页面. 下面是登录的代码: #c ...

  2. Python3发送webservice请求

    Python3使用suds-jurko库来发送webservice接口请求 导入请求webservice接口需要用到的包 pip install suds-jurko 第一步:导入所需要的包 from ...

  3. python3 get post请求Yunba RESTful API

    一:主要内容 获取云巴appkey和seckey 状态回复说明 get请求 post请求 二:获取云巴appkey和seckey 1. 注册云巴 在云巴官网,注册一个云巴账号,官网地址:https:/ ...

  4. Python3 使用requests请求,解码时出错:'utf8' codec can't decode byte 0x8b in position 1: invalid start byte

    requests请求的响应内容能够通过几个属性获得: response.text 为解码之后的内容,解码会根据响应的HTTP Header中的Content-Type选择字符集.例如 "'C ...

  5. python3 提取http请求response中的某个值

    在使用python3 request做接口测试的时候,想获取response的json中的某个值做断言时,发现request好像没有相关的方法 所以只好自己找写一个了.在我看来,json就是一个字典, ...

  6. python3中post请求里带list报错

    这个post请求的数据太长,一般data=,json=就够了. 但是今天这个一直报错,用json吧,报缺少参数,用data吧,报多余[. 后来改成data=,并把数据中的[] 用引号括起来," ...

  7. python3之POST请求URL

    方法一:使用requests模块 import requests as rq import json def funcpost(): url = 'http://www.***.com/' # 需要请 ...

  8. python3中post请求 json 数据

    post请求 #!/usr/bin/env python # -*- coding:utf-8 -*- import requests import json headers = { "Us ...

  9. Python3 使用requests请求,解码时出错:'utf8' codec can't decode byte 0x83 in position 1: invalid start byte

    requests请求的响应内容能够通过几个属性获得: response.text 为解码之后的内容,解码会根据响应的HTTP Header中的Content-Type选择字符集.例如 1 " ...

随机推荐

  1. C++ Primer Plus(四)

    完整阅读C++ Primer Plus 系统重新学习C++语言部分,记录重要但易被忽略的,关键但易被遗忘的. 友元.异常和其他 1.抛出异常类时,虽然catch的是一个引用,但是也会产生一次拷贝,因为 ...

  2. cp5200的一般步骤

    cp5200的一般步骤: 1.创建数据对象 hObj = CP5200_CommData_Create(nCommType, id, GetIDCode()); 2.生成所需要的数据,如 :生成设置亮 ...

  3. 《UNIX环境高级编程》(APUE) 笔记第七章 - 进程环境

    7 - 进程环境 Github 地址 1. main 函数 C 程序总是从 main 函数 开始执行: int main(int argc, char *argv[]); \(argc\) 为命令行参 ...

  4. Oracle 11gR2 待定的统计信息(Pending Statistic)

    Oracle 11gR2 待定的统计信息(Pending Statistic) 官档最权威: 发布优化器统计信息的用户界面 管理已发布和待处理的统计信息 实验先拖着.

  5. Git篇--将代码上传到git完整版

    1.注册github账号. 2.创建个人的github仓库,如图,   或者也可以进入个人中心去创建,   还可以直接点击右上角的“”+“”添加, 3.创建自己的Repository,如图: 4.新建 ...

  6. Cypress系列(13)- 详细介绍 Cypress Test Runner

    如果想从头学起Cypress,可以看下面的系列文章哦 https://www.cnblogs.com/poloyy/category/1768839.html 前言 Test Runner 也叫运行器 ...

  7. C#获取页面内容的几种方式

    常见的Web页面获取页面内容用 WebRequest 或者 HttpWebRequest 来操作 Http 请求. 例如,获取百度网站的 html 页面 var request = WebReques ...

  8. 《SpringBoot判空处理》接开@valid的面纱

    一.事有起因 我们在与前端交互的时候,一般会遇到字段格式校验及非空非null的校验,在没有SpringBoot注解的时候, 我们可能会在service进行处理: if(null == name){ t ...

  9. Let's GO(一)

    近来开始学Go,留此博客以记录学习过程,顺便鞭策自己更加努力. 人生苦短,Let's GO! Let's GO(一) Let's GO(二) Let's GO(三) Let's GO(四) 简单介绍 ...

  10. 阿里云OSS 服务端签名后直传之分片上传(结合element-ui的upload组件)

    分片上传(结合element-ui的upload组件实现自定义上传) async uploadFree(content){ let data = await this.getOssToken(); / ...