How to determine if POST is multipart-form or

polaris · · 312 次点击    
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
<p>I am new to Golang:</p> <p>I have found many articles on how to deal with multipart-form file uploads. I have an application in Python I am trying to port to golang that POSTs using multipart-form with file attachments or with application/URL-encoded if not files are present. What would be the best way to check to see if an HTTP POST is one or the other? </p> <hr/>**评论:**<br/><br/>nowbacktowork: <pre><p>Try checking the content type header.</p></pre>chzyer: <pre><p>A very primitive but useful and simple way: execute &#34;nc -l 12345&#34; in terminal, it will listen TCP on port 12345, now change your python application to post file to http://localhost:12345/xxx, you may see what it posted.</p></pre>gernest_: <pre><p>, I made quck functions to help you out.</p> <pre><code>//IsMultipart returns true if the given request is multipart forrm func IsMultipart(r *http.Request) bool { return r.Header.Get(&#34;Content-Type&#34;) == &#34;multipart/form-data&#34; } //IsURLEncoded returns true if the given form is url encoded func IsURLEncoded(r *http.Request) bool { return r.Header.Get(&#34;Content-Type&#34;) == &#34;application/x-www-form-urlencoded&#34; } </code></pre></pre>
312 次点击  
加入收藏 微博
0 回复
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传