dqwh0108 2014-09-22 17:06
浏览 25

无法读取请求xml正文元素值

I cannot seem to ready body element from XML request in my application.

I tried BodyParameter from Go-restulf package below but it doesn't seem to work and it just returns nil.

// BodyParameter parses the body of the request (once for typically a POST or a PUT) and returns the value of the given name or an error.
func (r *Request) BodyParameter(name string) (string, error) {
    err := r.Request.ParseForm()
    if err != nil {
        return "", err
    }
    return r.Request.PostFormValue(name), nil
}

Below is what I have currently on my file:

type Account struct {
    title, firstName, lastName, email, dob, countryCode, addrLevel, addUnitType, addrUnitNo, addrAllotment, addrBuildingNo, addrStreetName, addrStreetType, addrStreet1, addrStreet2, addrCity, countryState, addrPostcode, telephone, mobile string
    userName, password                                                                                                                                                                                                                        string
    currency                                                                                                                                                                                                                                float32
    challenge1                                                                                                                                                                                                                                string
    response1                                                                                                                                                                                                                                 string
    AdminUser, AdminPass, Version string
}

func (api *ApiResource) create(request *restful.Request, response *restful.Response) {
    account := &Account{AdminUser: user, AdminPass: pass, Version: version}
    err := request.ReadEntity(account)
    if err != nil {
        response.WriteErrorString(http.StatusInternalServerError, err.Error())
        return
    }

    fmt.Println(request.BodyParameter("UserName"))
}

Is there a reason why this isn't working as expected?

  • 写回答

1条回答 默认 最新

  • dougong5285 2014-09-23 04:44
    关注

    All your struct variables are not exported except AdminUser, AdminPass, Version.

    From http://golang.org/ref/spec#Exported_identifiers:

    An identifier may be exported to permit access to it from another package. An identifier is exported if both:

    1. the first character of the identifier's name is a Unicode upper case letter (Unicode class "Lu"); and
    2. the identifier is declared in the package block or it is a field name or method name.

    All other identifiers are not exported.

    评论

报告相同问题?

悬赏问题

  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题