httpbin.org – เว็บไซด์สำหรับวิเคราะห์การเรียก HTTP Request ของ Client
ในหลายๆครั้งเราต้องการตรวจสอบการเรียกหรือทดสอบ HTTP Request ที่เราสร้างจาก Client Browser หรือ Command Line หรือ Library ใดๆ ซึ่งแน่นอนว่าการจะ setup server ที่จะคอยแสดงรายละเอียดของ client นั้นทำไม่ยาก แต่มันมีเว็บไซด์ที่ทำไว้อยู่แล้ว ดังนั้นเราก็ไม่ต้องทำก็ได้ นั่นคือเว็บไซด์ httpbin.org นั่นเอง
โดยการใช้งานนั้นก็ง่ายๆ เราอยากได้ผลลัพธ์ของการเรียกอะไรก็เข้าไปตาม path ของเว็บไซด์ httpbin.org เช่น
หากเราต้องการให้แสดงผล User-Agent ของ Client ให้เราเข้าไปที่ http://httpbin.org/user-agent
1 |
curl http://httpbin.org/user-agent |
ก็จะได้ผลลัพธ์ออกมาเป็น user-agent ที่ทาง Web Server เห็นนั่นเอง (JSON Format)
หากต้องการทราบ IP จริงที่ Client ใช้ในการเชื่อมต่อเข้าไปยัง Server ก็ใช้เป็น
1 |
curl http://httpbin.org/ip |
ก็จะได้ผลลัพธ์ (HTTP Response) เป็น IP ของเราที่ใช้เชื่อมต่อนั่นเอง
โดย page ทั้งหมดของ httpbin มีดังนี้
/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/encoding/utf8
Returns page containing UTF-8 data./gzip
Returns gzip-encoded data./deflate
Returns deflate-encoded data./status/:code
Returns given HTTP Status code./response-headers?key=val
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./absolute-redirect/:n
302 Absolute 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 min(n, 100) lines./delay/:n
Delays responding for min(n, 10) seconds./drip?numbytes=n&duration=s&delay=s&code=code
Drips data over a duration after an optional initial delay, then (optionally) returns with the given status code./range/1024?duration=s&chunk_size=code
Streams n bytes, and allows specifying a Range header to select a subset of the data. Accepts a chunk_size and request durationparameter./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./image
Returns page containing an image based on sent Accept header./image/png
Returns page containing a PNG image./image/jpeg
Returns page containing a JPEG image./image/webp
Returns page containing a WEBP image./image/svg
Returns page containing a SVG image./forms/post
HTML form that submits to /post/xml
Returns some XML
หากเราต้องการนำ httpbin ไปสร้างเป็น web server ของตัวเองสามารถทำได้โดย
1 |
pip install httpbin |
จากนั้นสร้าง Web Server ขึ้นมาเป็น
1 |
gunicorn httpbin:app |
จากนั้นเข้าใช้งานผ่าน Port 8000 ได้เลยครับ
Source:: httpbin.org