使用HTTPBin測試HTTP庫

介紹

HTTP庫的測試一般來說較為繁瑣,一些同學(xué)較為熟悉的RequestBin雖然好用,但只能測試POST,且無法控制其response岩馍。HTTPBin是以Python+Flask寫的一款工具,它c(diǎn)over了各類的HTTP場景抖韩,且每個(gè)接口一定都有返回蛀恩。

安裝方法

使用pip工具分別安裝httpbin與guicorn,guicorn是一個(gè)wsgi http服務(wù)器茂浮,詳見guicorn 是什么双谆。

#安裝pip工具
[root@localhost ~]# wget https://bootstrap.pypa.io/get-pip.py
[root@localhost ~]# python get-pip.py
#分別使用pip工具安裝guicorn與httpbin
[root@localhost ~]# pip install httpbin
[root@localhost ~]# pip install guicorn
#啟動(dòng)httpbin
[root@localhost ~]# gunicorn -b :8000 httpbin:app
[2017-07-11 16:25:29 +0000] [21088] [INFO] Starting gunicorn 19.7.1
[2017-07-11 16:25:29 +0000] [21088] [INFO] Listening at: http://0.0.0.0:8000 (21088)
[2017-07-11 16:25:29 +0000] [21088] [INFO] Using worker: sync
[2017-07-11 16:25:29 +0000] [21093] [INFO] Booting worker with pid: 21093
#訪問httpbin主頁面
[root@localhost ~]# lynx localhost:8000
image

接口列表

Endpoint Descirption
/ This page.
/ip Returns Origin IP.
/user-agent Returns user-agent.
/headers Returns header dict.
/get Returns GET data.
/post Returns POST data.
/patch Returns PATCH data.
/put Returns PUT data.
/delete Returns DELETE data
/gzip Returns gzip-encoded data.
/deflate Returns deflate-encoded data.
/status/:code Returns given HTTP Status code.
/response-headers Returns given response headers.
/redirect/:n 302 Redirects n times.
/redirect-to?url=foo 302 Redirects to the foo URL.
/relative-redirect/:n 302 Relative redirects n times.
/cookies Returns cookie data.
/cookies/set?name=value Sets one or more simple cookies.
/cookies/delete?name Deletes one or more simple cookies.
/basic-auth/:user/:passwd Challenges HTTPBasic Auth.
/hidden-basic-auth/:user/:passwd 404'd BasicAuth.
/digest-auth/:qop/:user/:passwd Challenges HTTP Digest Auth.
/stream/:n Streams n – 100 lines.
/delay/:n Delays responding for n – 10 seconds.
/drip Drips data over a duration after an optional initial delay, then (optionally) returns with the given status code.
/range/:n Streams n bytes, and allows specifying a Range header to select a subset of the data. Accepts a chunk_size and request duration parameter.
/html Renders an HTML Page.
/robots.txt Returns some robots.txt rules.
/deny Denied by robots.txt file.
/cache Returns 200 unless an If-Modified-Since or If-None-Match header is provided, when it returns a 304.
/cache/:n Sets a Cache-Control header for n seconds.
/bytes/:n Generates n random bytes of binary data, accepts optional seed integer parameter.
/stream-bytes/:n Streams n random bytes of binary data, accepts optional seed and chunk_size integer parameters.
/links/:n Returns page containing n HTML links.
/forms/post HTML form that submits to /post
/xml Returns some XML
/encoding/utf8 Returns page containing UTF-8 data.

例子

[root@localhost ~]# curl http://httpbin.org/ip
{
  "origin": "218.189.127.78"
}
[root@localhost ~]# curl http://httpbin.org/user-agent
{
  "user-agent": "curl/7.29.0"
}
[root@localhost ~]# curl https://httpbin.org/get?show_env=1
{
  "args": {
    "show_env": "1"
  }, 
  "headers": {
    "Accept": "*/*", 
    "Connect-Time": "0", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "Total-Route-Time": "0", 
    "User-Agent": "curl/7.29.0", 
    "Via": "1.1 vegur", 
    "X-Forwarded-For": "218.189.127.78", 
    "X-Forwarded-Port": "443", 
    "X-Forwarded-Proto": "https", 
    "X-Request-Id": "392e0fda-5f1b-4cc8-8131-77967bfee9db", 
    "X-Request-Start": "1499761771703"
  }, 
  "origin": "218.189.127.78", 
  "url": "https://httpbin.org/get?show_env=1"
}
[root@localhost ~]# curl -I http://httpbin.org/status/418
HTTP/1.1 418 I'M A TEAPOT
Connection: keep-alive
Server: meinheld/0.6.1
Date: Tue, 11 Jul 2017 08:29:40 GMT
X-Processed-Time: 0.000515937805176
Access-Control-Allow-Origin: *
X-More-Info: http://tools.ietf.org/html/rfc2324
Access-Control-Allow-Credentials: true
X-Powered-By: Flask
Content-Length: 135
Via: 1.1 vegur

[root@localhost ~]# curl http://httpbin.org/get
{
  "args": {}, 
  "headers": {
    "Accept": "*/*", 
    "Connection": "close", 
    "Host": "httpbin.org", 
    "User-Agent": "curl/7.29.0"
  }, 
  "origin": "218.189.127.78", 
  "url": "http://httpbin.org/get"
}

參考

1、 kennethreitz/httpbin

2席揽、guicorn是什么

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末佃乘,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子驹尼,更是在濱河造成了極大的恐慌趣避,老刑警劉巖,帶你破解...
    沈念sama閱讀 219,110評(píng)論 6 508
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件新翎,死亡現(xiàn)場離奇詭異程帕,居然都是意外死亡住练,警方通過查閱死者的電腦和手機(jī),發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,443評(píng)論 3 395
  • 文/潘曉璐 我一進(jìn)店門愁拭,熙熙樓的掌柜王于貴愁眉苦臉地迎上來讲逛,“玉大人,你說我怎么就攤上這事岭埠≌祷欤” “怎么了?”我有些...
    開封第一講書人閱讀 165,474評(píng)論 0 356
  • 文/不壞的土叔 我叫張陵惜论,是天一觀的道長许赃。 經(jīng)常有香客問我,道長馆类,這世上最難降的妖魔是什么混聊? 我笑而不...
    開封第一講書人閱讀 58,881評(píng)論 1 295
  • 正文 為了忘掉前任,我火速辦了婚禮乾巧,結(jié)果婚禮上句喜,老公的妹妹穿的比我還像新娘。我一直安慰自己沟于,他們只是感情好咳胃,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,902評(píng)論 6 392
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著旷太,像睡著了一般展懈。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上泳秀,一...
    開封第一講書人閱讀 51,698評(píng)論 1 305
  • 那天标沪,我揣著相機(jī)與錄音榄攀,去河邊找鬼嗜傅。 笑死,一個(gè)胖子當(dāng)著我的面吹牛檩赢,可吹牛的內(nèi)容都是我干的吕嘀。 我是一名探鬼主播,決...
    沈念sama閱讀 40,418評(píng)論 3 419
  • 文/蒼蘭香墨 我猛地睜開眼贞瞒,長吁一口氣:“原來是場噩夢(mèng)啊……” “哼偶房!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起军浆,我...
    開封第一講書人閱讀 39,332評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤棕洋,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后乒融,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體掰盘,經(jīng)...
    沈念sama閱讀 45,796評(píng)論 1 316
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡摄悯,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,968評(píng)論 3 337
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了愧捕。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片奢驯。...
    茶點(diǎn)故事閱讀 40,110評(píng)論 1 351
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖次绘,靈堂內(nèi)的尸體忽然破棺而出瘪阁,到底是詐尸還是另有隱情,我是刑警寧澤邮偎,帶...
    沈念sama閱讀 35,792評(píng)論 5 346
  • 正文 年R本政府宣布管跺,位于F島的核電站,受9級(jí)特大地震影響钢猛,放射性物質(zhì)發(fā)生泄漏伙菜。R本人自食惡果不足惜罗岖,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,455評(píng)論 3 331
  • 文/蒙蒙 一导梆、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧赠法,春花似錦壶愤、人聲如沸淑倾。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,003評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽娇哆。三九已至,卻和暖如春勃救,著一層夾襖步出監(jiān)牢的瞬間碍讨,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,130評(píng)論 1 272
  • 我被黑心中介騙來泰國打工蒙秒, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留勃黍,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,348評(píng)論 3 373
  • 正文 我出身青樓晕讲,卻偏偏與公主長得像覆获,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子瓢省,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,047評(píng)論 2 355

推薦閱讀更多精彩內(nèi)容