導航:首頁 > 編程語言 > python處理http請求

python處理http請求

發布時間:2022-04-03 15:17:14

Ⅰ 如何用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 post 的請求參數

import urllib2
import urllib

#定義一個要提交的數據數組(字典)
data = {}
data['username'] = 'zgx030030'
data['password'] = '123456'

#定義post的地址
url = 'http://www.test.com/post/'
post_data = urllib.urlencode(data)

#提交,發送數據
req = urllib2.urlopen(url, post_data)

#獲取提交後返回的信息
content = req.read()

以上。

Ⅲ python 什麼是http非同步請求

http請求為耗時IO操作,如果同步阻塞的話,進程會等待請求完成。
非同步的話,進程會發出http請求(請求以後不需要cpu),然後跳轉到別的任務,直到http請求完成,再調回來繼續處理得到的http回應。
最經典的例子就是燒水,同步阻塞就是你一直蹲在爐子旁邊等待水燒開,而非同步是把水壺放在爐子上,等水開了以後茶壺會叫,這時候你聽到聲音就會回來處理開水~

Ⅳ 使用python的requests庫運行http請求,請問如圖的報錯是什麼原因,要怎麼解決的

post的參數順序再檢查確認一下,可以使用類似data=data,header=head的方式賦值避免混淆。

Ⅳ python 怎麼處理http post 的請求參數

import httplib, urllib
from urlparse import urlparse
def httppost(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()
print response.status
print response.reason
print response.read()
print response.getheaders()
except Exception, e:
print e
finally:
if httpClient:
httpClient.close()

Ⅵ python 怎麼處理http post 的請求參數

import httplib, urllib
from urlparse import urlparse

def httppost(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()
print response.status
print response.reason
print response.read()
print response.getheaders()
except Exception, e:
print e
finally:
if httpClient:
httpClient.close()

Ⅶ python里同時發送多個http請求怎麼弄

多個同進的話,使用多線程就可以,也可以使用多進程,多進程可以更好的利用多核CPU的能力。

閱讀全文

與python處理http請求相關的資料

熱點內容
優信二手車解壓後過戶 瀏覽:61
Windows常用c編譯器 瀏覽:778
關於改善國家網路安全的行政命令 瀏覽:833
安卓如何下載網易荒野pc服 瀏覽:654
javainetaddress 瀏覽:104
蘋果4s固件下載完了怎麼解壓 瀏覽:1002
命令zpa 瀏覽:285
python編譯器小程序 瀏覽:944
在app上看視頻怎麼光線調暗 瀏覽:540
可以中文解壓的解壓軟體 瀏覽:592
安卓卸載組件應用怎麼安裝 瀏覽:912
使用面向對象編程的方式 瀏覽:339
程序員項目經理的年終總結範文 瀏覽:929
內衣的加密設計用來幹嘛的 瀏覽:432
淮安數據加密 瀏覽:292
魔高一丈指標源碼 瀏覽:982
松下php研究所 瀏覽:168
c回調java 瀏覽:399
夢幻端游長安地圖互通源碼 瀏覽:745
電腦本地文件如何上傳伺服器 瀏覽:313