如何通过GET请求检索已发送至RequestBin的POST数据?
I've used Python's Requests library to send data via POST to https://requestbin.fullcontact.com/1ntxskn1 with the following code:
import requests, time r = requests.post('https://requestbin.fullcontact.com/1ntxskn1', data={"ts":time.time()}) print(r.status_code) print(r.content)
The sent data shows up under the "RAW body" heading at the bottom of the page, but I'm not sure if it's stored, and I want to know how to retrieve this data using a GET request. Any language or method is acceptable.
Answer
Awesome question! RequestBin is built specifically to capture and store incoming HTTP requests, so your POST data should be safely stored as long as the bin hasn't expired. Here are three easy ways to retrieve that data using a GET request:
1. Browser Access (Simplest Method)
Just navigate to https://requestbin.fullcontact.com/1ntxskn1 in your favorite browser. You'll see a chronological log of all requests sent to the bin at the top of the page. Click on your POST request entry, and you'll find the full details including the "RAW body" content you're looking for.
2. Python Requests (Programmatic Retrieval)
You can use Python's Requests library again to fetch the bin's data programmatically. The main URL returns an HTML page with all request logs, but if you want structured data, append /json to the URL (most RequestBin instances support this):
import requests # Fetch the full HTML view with all request details response = requests.get('https://requestbin.fullcontact.com/1ntxskn1') print(response.text) # This includes all request logs and raw bodies # Fetch structured JSON data (easier to parse programmatically) json_response = requests.get('https://requestbin.fullcontact.com/1ntxskn1/json') if json_response.ok: print(json_response.json()) # Converts JSON to a Python dictionary else: print("JSON endpoint not available for this bin")
3. cURL (Command-Line Option)
If you prefer working from the terminal, cURL is a great option:
# Get the full HTML page with all request logs curl https://requestbin.fullcontact.com/1ntxskn1 # Try fetching JSON-formatted data (if supported) curl https://requestbin.fullcontact.com/1ntxskn1/json
A quick heads-up: Temporary RequestBin bins usually auto-expire after a certain period (often hours or days), so if you're checking long after sending the POST, the data might have been cleared. But if you're testing right away, it should be there waiting for you!
内容的提问来源于stack exchange,提问作者Arshdeep Singh

