① 如何用python写一个http post请求

python发送post和get请求
get请求:
使用get方式时,请求数据直接放在url中。
方法一、
importurllib
importurllib2
url="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa"</a>
req=urllib2.Request(url)
printreq
res_data=urllib2.urlopen(req)
res=res_data.read()
printres
方法二、
importhttplib
url="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py?ServiceCode=aaaa"</a>
conn=httplib.HTTPConnection("192.168.81.16")
conn.request(method="GET",url=url)
response=conn.getresponse()
res=response.read()
printres
post请求:
使用post方式时,数据放在data或者body中,不能放在url中,放在url中将被忽略。
方法一、
importurllib
importurllib2
test_data={'ServiceCode':'aaaa','b':'bbbbb'}
test_data_urlencode=urllib.urlencode(test_data)
requrl="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py"</a>
req=urllib2.Request(url=requrl,data=test_data_urlencode)
printreq
res_data=urllib2.urlopen(req)
res=res_data.read()
printres

方法二、
importurllib
importhttplib
test_data={'ServiceCode':'aaaa','b':'bbbbb'}
test_data_urlencode=urllib.urlencode(test_data)
requrl="<ahref="http://192.168.81.16/cgi-bin/python_test/test.py""target="_blank">http://192.168.81.16/cgi-bin/python_test/test.py"</a>
headerdata={"Host":"192.168.81.16"}
conn=httplib.HTTPConnection("192.168.81.16")
conn.request(method="POST",url=requrl,body=test_data_urlencode,headers=headerdata)
response=conn.getresponse()
res=response.read()
printres

② python http接口测试脚本怎么写

根据Testcase的具体业务逻辑用事先准备好的测试数据去调用封装好的API接口,验证实际返回结果是否与预期返回结果一致.
测试数据可以以各种形式存放,如Excel数据表:
TestCaseName uname method Expected Result
TestCase1 aaaa GET ....
TestCase2 aaaa POST ....
TestCase3 bbbb GET ....
... ... ... ....

③ 如何用Python写一个http post请求

用这个:class urllib2.Request(url[, data][, headers][, origin_req_host][, unverifiable])

其中data就是post的内容。
从别的地方找了个例子一看就能懂。

import urllib
import urllib2
url = 'http://umbra.nascom.nasa.gov/cgi-bin/eit-catalog.cgi'
values = {'obs_year':'2011','obs_month':'March',
'obs_day':'8','start_year':'2011'
,'start_month':'March','start_day':'8'
,'start_hour':'All Hours','stop_year':'2011'
,'stop_month':'March','stop_day':'8'
,'stop_hour':'All Hours','xsize':'All'
,'ysize':'All','wave':'all'
,'filter':'all','object':'all'
,'xbin':'all','ybin':'all'
,'highc':'all'}
data = urllib.urlencode(values)
print data
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)
the_page = response.read()
print the_page

④ python http接口测试脚本怎么写

根据Testcase的具体业务逻辑用事先准备好的测试数据去调用封装好的API接口,验证实际返回结果是否与预期返回结果一致.
测试数据可以以各种形式存放,如Excel数据表:
TestCaseName
uname
method
Expected
Result
TestCase1
aaaa
GET
....
TestCase2
aaaa
POST
....
TestCase3
bbbb
GET
....
APK文件的解包打包和修改
相信每位玩机的人对APK文件都不陌生。你可能每天都与APK文件打交道,无论是安装和卸载有用的应用工具、插件、好玩的游戏等等。
你可曾知道这些每天都伴随着你的APK文件是什么吗?怎样对它们作些修改呢?比如说:对英文版进行汉化、修改功能、修改文字描述、去掉广告等等。本文介绍APK的基本知识、结构、APK文件的解包、打包及签名,以及对APK文件的常规修改。

⑤ python 怎么实现http服务器

简而言之,它是在物理服务器上搭建的一个网络连接服务器(networking server),永久地等待客户端发送请求。当服务器收到请求之后,它会生成响应并将 其返回至客户端。客户端与服务器之间的通信,是以HTTP协议进行的。客户端可以是浏览器,也可以是任何支持HTTP协议的软件
那么,网络服务器的简单实现形式会是怎样的呢?下面是我对此的理解。示例代码使用Python语言实现,不过即使你不懂Python语言,你应该也可以从代码和下面的 解释中理解相关的概念:
?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22

import socket

HOST, PORT = '', 8888

listen_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
listen_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
listen_socket.bind((HOST, PORT))
listen_socket.listen(1)
print 'Serving HTTP on port %s ...' % POR

⑥ 如何用Python写一个http post请求

import urllib2
import urllib

#定义来一个要提交的自数据数组(字典)
data = {}
data['username'] = 'zgx030030'
data['password'] = '123456'

#定义post的地址
url = '<a href="http://www.test.com/post/'" target="_blank">http://www.test.com/post/'</a>
post_data = urllib.urlencode(data)

#提交,发送数据
req = urllib2.urlopen(url, post_data)

#获取提交后返回的信息
content = req.read(

⑦ 如何用Python写一个http post请求

defRequestCenter(data,url,web="127.0.0.1",port=9228):

headDic={}
headDic[REQUEST_HEAD_LENGTH]=len(data)

tempList=[]
tempList.append(headDic)
tempList.extend(data)

#远程访问
count=0
jsonData=json.mps(tempList)
headers={"Content-type":"application/json"}
state=-1
whilecount<1:
com=httplib.HTTPConnection(web,port,True)
com.request("POST",url,jsonData,headers)
response=com.getresponse()
time.sleep(0.5)
infoList=[]
state=response.status
if200<=state<300:
infoList=json.loads(response.read())
com.close()
break
else:
count+=1
com.close()
returninfoList

⑧ python 爬虫怎么提供http接口

使用web框架,来做爬虫调度,同时对外提供api

⑨ 如何用Python写一个http post请求

importhttplib,urllib
fromurlparseimporturlparse


defhttppost(url,**kwgs):
httpClient=None
conn=urlparse(url)
try:
params=urllib.urlencode(dict(kwgs))
header={"Content-type":"application/x-www-form-urlencoded",
"Accept":"text/plain",}

httpClient=httplib.HTTPConnection(conn.netloc,conn.port,timeout=30)
httpClient.request("POST",conn.path,params,header)

response=httpClient.getresponse()
printresponse.status
printresponse.reason
printresponse.read()
printresponse.getheaders()
exceptException,e:
printe
finally:
ifhttpClient:
httpClient.close()

⑩ 如何用Python写一个http post请求

:import urllib2 import urllib #定义一个要提交的数据数组(字典) data = {} data['username'] = 'zgx030030' data['password'] = '123456' #定义post的地址版 url = 'http://www.test.com/post/' post_data = urllib.urlencode(data) #提交,发权送.