urllib2 get post 博客分类: ptython python
程序员文章站
2024-03-13 10:00:39
...
python post,get 的 方法
post #参数有 data 就是 post,没有data 是 get
1
url="https://api.ext.m-m10010.com/open/unicom/BatchQueryTerminal"
data = {"userId":MLB_USERID,"num":imsis,"num_type":"imsi","timestamp":dt,"sign":token}
req = urllib2.Request(url)
req.add_header("Content-Type","application/json") #有些需要 headers 不然会失败
res = urllib2.urlopen(req,json.dumps(data))
print res.read()
2
headers = {"Content-Type":"application/json"}
req = urllib2.Request(
url,
json.dumps(data),
headers
)
res = urllib2.urlopen(req)
prin res.read()
3 # 不需要headers
res = urllib2.urlopen(
url = url,
data = json.dumps(data),
timeout = 5
)
print res.read()
4 #需要urlencode
data = urllib.urlencode(data)
res = urllib2.urlopen(url=url,data=data,timeout=5)
post #参数有 data 就是 post,没有data 是 get
1
url="https://api.ext.m-m10010.com/open/unicom/BatchQueryTerminal"
data = {"userId":MLB_USERID,"num":imsis,"num_type":"imsi","timestamp":dt,"sign":token}
req = urllib2.Request(url)
req.add_header("Content-Type","application/json") #有些需要 headers 不然会失败
res = urllib2.urlopen(req,json.dumps(data))
print res.read()
2
headers = {"Content-Type":"application/json"}
req = urllib2.Request(
url,
json.dumps(data),
headers
)
res = urllib2.urlopen(req)
prin res.read()
3 # 不需要headers
res = urllib2.urlopen(
url = url,
data = json.dumps(data),
timeout = 5
)
print res.read()
4 #需要urlencode
data = urllib.urlencode(data)
res = urllib2.urlopen(url=url,data=data,timeout=5)
推荐阅读
-
urllib2 get post 博客分类: ptython python
-
python利用urllib和urllib2访问http的GET/POST详解
-
python利用urllib和urllib2访问http的GET/POST详解
-
Get和Post的编码问题 博客分类: Java系统 Java 编码
-
Get和Post的编码问题 博客分类: Java系统 Java 编码
-
python如何使用urllib/urllib2访问http的GET及POST详解
-
python如何使用urllib/urllib2访问http的GET及POST详解
-
python学习之利用urllib和urllib2访问http的GET/POST详解
-
python学习之利用urllib和urllib2访问http的GET/POST详解