<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>HTTP on Blogs (码码要洗手)</title><link>https://navydev.top/blog/tags/http/</link><description>Recent content in HTTP on Blogs (码码要洗手)</description><generator>Hugo -- gohugo.io</generator><language>zh-CN</language><lastBuildDate>Fri, 23 Aug 2024 17:50:18 +0800</lastBuildDate><atom:link href="https://navydev.top/blog/tags/http/index.xml" rel="self" type="application/rss+xml"/><item><title>HttpBin</title><link>https://navydev.top/blog/httpbin/</link><pubDate>Fri, 23 Aug 2024 17:50:18 +0800</pubDate><guid>https://navydev.top/blog/httpbin/</guid><description>&lt;img src="https://navydev.top/images/covers/httpbin.webp" alt="Featured image of post HttpBin" /&gt;&lt;p&gt;&lt;strong&gt;HttpBin&lt;/strong&gt; is a simple HTTP request &amp;amp; response service. It is incredibly useful when you need to verify if your HTTP client (curl, Python requests, Go http, etc.) is sending the data you expect.&lt;/p&gt;
&lt;h2 id="common-endpoints"&gt;Common Endpoints
&lt;/h2&gt;&lt;h3 id="1-inspect-request-data"&gt;1. Inspect Request Data
&lt;/h3&gt;&lt;p&gt;Verify headers, query params, and body.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET /get&lt;/code&gt;: Returns GET arguments.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;POST /post&lt;/code&gt;: Returns POST data.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;PUT /put&lt;/code&gt;: Returns PUT data.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;strong&gt;Example:&lt;/strong&gt;
Check if your query parameters are encoded correctly.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;curl &lt;span style="color:#e6db74"&gt;&amp;#34;https://httpbin.org/get?name=navy&amp;amp;age=30&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;Response:&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-json" data-lang="json"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;{
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;args&amp;#34;&lt;/span&gt;: {
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;age&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;30&amp;#34;&lt;/span&gt;,
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#f92672"&gt;&amp;#34;name&amp;#34;&lt;/span&gt;: &lt;span style="color:#e6db74"&gt;&amp;#34;navy&amp;#34;&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; },
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt; &lt;span style="color:#960050;background-color:#1e0010"&gt;...&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;}
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="2-inspect-headers"&gt;2. Inspect Headers
&lt;/h3&gt;&lt;p&gt;Check if your custom headers are actually being sent.&lt;/p&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;curl -H &lt;span style="color:#e6db74"&gt;&amp;#34;X-Custom-Header: value&amp;#34;&lt;/span&gt; https://httpbin.org/headers
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="3-test-status-codes"&gt;3. Test Status Codes
&lt;/h3&gt;&lt;p&gt;Check how your application handles different HTTP errors.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET /status/:code&lt;/code&gt;: Returns given HTTP Status code.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight"&gt;&lt;pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;-webkit-text-size-adjust:none;"&gt;&lt;code class="language-bash" data-lang="bash"&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Test 404 handling&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;curl -I https://httpbin.org/status/404
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;&lt;span style="color:#75715e"&gt;# Test 500 handling&lt;/span&gt;
&lt;/span&gt;&lt;/span&gt;&lt;span style="display:flex;"&gt;&lt;span&gt;curl -I https://httpbin.org/status/500
&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;h3 id="4-test-response-formats"&gt;4. Test Response Formats
&lt;/h3&gt;&lt;ul&gt;
&lt;li&gt;&lt;code&gt;GET /json&lt;/code&gt;: Returns a simple JSON object.&lt;/li&gt;
&lt;li&gt;&lt;code&gt;GET /xml&lt;/code&gt;: Returns a simple XML document.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2 id="debugging-scenario"&gt;Debugging Scenario
&lt;/h2&gt;&lt;p&gt;Imagine you have a complex XML payload that fails on the production server. You can&amp;rsquo;t see what the server receives.&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;Change the URL&lt;/strong&gt;: Point your client to &lt;code&gt;https://httpbin.org/post&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Send Request&lt;/strong&gt;: Trigger the action in your app.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Inspect Response&lt;/strong&gt;: HttpBin will echo back &lt;em&gt;exactly&lt;/em&gt; what it received (headers, body content type, raw string).&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;Compare&lt;/strong&gt;: You might find that your library added an extra wrapper or the encoding was wrong.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Useful URL: &lt;a class="link" href="https://httpbin.org/" target="_blank" rel="noopener"
&gt;https://httpbin.org/&lt;/a&gt;&lt;/p&gt;</description></item></channel></rss>