仅在多个get参数请求中返回第一个参数 [英] Only returning first parameter in multiple get parameter request
问题描述
我有以下api curl请求:
I have the following api curl request:
curl --request GET http://127.0.0.1/juris?d=11111& ; a = 22222
在我的 http处理程序函数
内部,该函数具有以下参数: w http.ResponseWriter,r * http.Request
我有代码:
Inside my http handler function
which has the arguments: w http.ResponseWriter,r *http.Request
i have the code:
defer r.Body.Close()
keys,ok := r.URL.Query()["d"]
if !ok{
respondWithError(w,http.StatusBadRequest,"InvalidQuery")
return
}
dnisQuery := string(keys[0])
akeys,aok := r.URL.Query()["a"]
if !aok{
respondWithError(w,http.StatusBadRequest,"InvalidQuery")
return
}
aniQuery := string(akeys[0])
它验证并传递第一个查询参数 d $ c $的正确值c>,但是第二个参数
a
失败,带有 InvalidQuery
It validates and passes the correct value for the first query parameter d
but it fails for the second parameter a
with an InvalidQuery
不确定我的操作不正确。
Not sure what im doing incorrectly.
推荐答案
如果您发出
curl --request GET http://127.0.0.1/juris?d=11111&a=22222
外壳将看到
curl --request GET http://127.0.0.1/juris?d=11111 & a=22222
并运行第一个命令作为后台作业,这就是 a
部分被忽略。 (这实际上导致shell将变量 a
设置为 22222
。)要使其正常工作,您必须转义您的网址:
and run the first command as a background job, that's why the a
part was ignored. (It actually resulted in the shell setting the variable a
to 22222
.) To get it to work, you have to escape your URL:
curl --request GET 'http://127.0.0.1/juris?d=11111&a=22222'
这篇关于仅在多个get参数请求中返回第一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!