我有一个结构:
type Credentials struct {
Username string `json:"username"`
Password string `json:"password"`
ApplicationId string `json:"application_id"`
ApplicationKey string `json:"application_key"`
}
我已经标记了我的字段以小写它们。
但是,每当我包含应用程序标签时,这些字段都会变为空,即在我的 POST 请求中,我得到
{ application_id: '',
application_key: '',
password: 'myPassword',
username: 'myUsername'
}
但是如果我删除任何一个标签(因此删除ApplicatinonId或ApplicationKey标记),那么该字段确实会显示
这是我设置结构的方法:
func getCredentials() Credentials {
raw, err := ioutil.ReadFile(os.Getenv("BASE_PATH") + FILE_Credentials)
if err != nil {
log.Warn("Could not read credentials file: %s", err.Error())
os.Exit(1)
}
var credentials Credentials
json.Unmarshal(raw, &credentials)
return credentials
}
我的凭证json文件是:
{
"Username": "myUsername",
"Password": "myPassowrd",
"ApplicationId": "someID",
"ApplicationKey": "someString"
}
然后,我发布我的数据:
credentials := getCredentials()
url := GetLoginURL()
resp, body, requestErr := gorequest.New().
Post(url).
Send(credentials).
End()
但是在服务器上,我同时得到application_id和application_key作为空字符串。但是如果我删除相应的标签,那么该字段将被发布
守候你守候我
翻过高山走不出你
精慕HU
随时随地看视频慕课网APP
相关分类