<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 "nc -l 12345" 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("Content-Type") == "multipart/form-data"
}
//IsURLEncoded returns true if the given form is url encoded
func IsURLEncoded(r *http.Request) bool {
return r.Header.Get("Content-Type") == "application/x-www-form-urlencoded"
}
</code></pre></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传