2016-12-16 163 views
0

我正在获取此Error = mime: expected slash after first token 下面的一些细节。Golang - ParseForm; err = mime:第一个令牌后的预期斜杠

目标是一个登录表单,用户名和密码 可以从POST中提取。

我还测试了卷曲后和静态HTML表单 - >同样的问题= mime: expected slash after first token

片段旅途代码:

log.Printf("\n\n\t[loginH()] - POST method ...\n") 
err := r.ParseForm() 
if err != nil { 
     // Handle error here via logging and then return 
     DebugLog.Printf("[loginH()] - ERROR: with r.ParseForm. (err=%v)\n", err) 
     log.Printf("[loginH()] - ERROR: with r.ParseForm. (err=%v)\n", err) 
} 
username := r.Form["username"] 
passwd := r.Form["passwd"] 
log.Printf("[loginH()] - r.Form ... username=%s and passwd=%s\n",username,passwd) 

的HTML /的形式是:

<form method="POST" action="/login"> 
    <input type="text" name="username" placeholder="Email Address"/> 
    <input type="password" name="passwd" placeholder="Password"/> 
    <input type="submit" id="loginBtn" name="login" value="Logon"/> 
</form> 

输出:

2016/12/15 21:36:07 [loginH()] - POST method ... 
2016/12/15 21:36:07 [loginH()] - ERROR: with r.ParseForm. (err=mime: expected slash after first token) 
2016/12/15 21:36:07 [loginH()] - r.Form ... username= and passwd= 

预先感谢任何指点/信息/启示。

r.Form是空

+0

小更新 - 使用 –

+0

@Motakjuq - 感谢您的文本清理。 –

回答

0

此错误来源于mediatype.go 85线。您可能会在内部调用ParseMediaType方法时发生此错误。从那里看起来好像你的静态表单或curl没有正确设置Content-Type或Content-Disposition的某些值。请检查这些标题是否有问题的值。

从文档:

// ParseMediaType parses a media type value and any optional 
// parameters, per RFC 1521. Media types are the values in 
// Content-Type and Content-Disposition headers (RFC 2183). 
// On success, ParseMediaType returns the media type converted 
// to lowercase and trimmed of white space and a non-nil map. 
// The returned map, params, maps from the lowercase 
// attribute to the attribute value with its case preserved. 
+0

谢谢!我挖入源mediatype.go,找到该字符串。 您的笔记有助于查明问题,有一个代理正在修改Content-Type标题。我移动了服务器,并能够确认表单邮件正在工作。 我很感谢你的时间。 –