나는 문제로 실행했습니다
내가 내 beego
응용 프로그램Beego multipart/form-data 헤더로 제출 된 params에 액세스하는 방법? 다음과 같이
내 컨트롤러에서컬 http://localhost:8080/controller/path -X POST -H '콘텐츠 유형에
curl
요청을 만들 때 : 다중/폼 데이터를; 문자셋 = UTF-8 '-F "[email protected]; 파일 이름 = file.csv"-F "이름 = 최초의"
name
PARAM에 액세스 할
,하지만 난 시도
FUNC (ㄴ * 컨트롤러) 경로() {
...
VAR 이름 문자열
c.Ctx.Input.Bind (& 이름 "이름") 또는 내가
//를했습니다 시도 '이름 : = c.GetString ("이름")'
...
}
결과는 항상 name
변수로 빈 문자열입니다.
내가 뭘 잘못하고 있니? 이 경우 params에 어떻게 액세스 할 수 있습니까? 제발 어떤 조언을 환영합니다! 나는 운없이, Parse to struct
접근을 시도했습니다 1
업데이트 ... 코멘트로
type DataParams struct {
Name string `form:"name"`
}
cLDP := DataParams{}
if err := c.ParseForm(&cLDP); err != nil {
return ret, err
}
업데이트 2
, 나는
c.Ctx.Input.ParseFormOrMulitForm(99999)
var name string
c.Ctx.Input.Bind(&name, "name")
을 시도했습니다 업데이트 3 모두 잃어버린 후
...
name := c.Ctx.Input.Query("name")
params := c.Ctx.Input.Params()
name2 := c.GetString("name")
c.Ctx.Input.ParseFormOrMulitForm(99999)
params2 := c.Ctx.Input.Params()
fmt.Println("Debug 2->", name)
fmt.Println("Debug 5->", name2)
fmt.Println("Debug 3->", params)
fmt.Println("Debug 4->", params2)
출력은 내가 c.Ctx.Input.RequestBody
이 놀라 울 정도로 빈
그리고 아직도 행운하지 그것을 사용하는 경우에는 이름 PARAM이
업데이트 4
을 감지되지
Debug 2->
Debug 3-> map[...]
Debug 4-> map[...]
Debug 5->
입니다 : (
'Bind'를 호출하기 전에 입력시 [ParseFormOrMulitForm] (https://godoc.org/github.com/astaxie/beego/context#BeegoInput.ParseFormOrMulitForm) 메소드를 호출 해보십시오. Mu ** li ** t typo는 내 것이 아니므로이 방법이 정의 된 것입니다. – mkopriva
행운, 업데이트를 참조하십시오 – Elmor