dsirr48088 2016-04-01 14:57
浏览 75

使用golang http库提交表单

Oke, I'm currently trying to login in to my school website, with my own Crawler. Altough they have some protection against login. First I do a Get request to the Website so I get the token from the hidden Input field. That token I use in my next Post request to login to the url! But for some reason the http response is that I cannot resubmit the form. But with doing the same in Postman rest client (chrome plugin) I can login!

When I try to submit a form to this url:

postLoginUrl = "?username=%s&password=%s&submit=inloggen&_eventId=submit&credentialsType=ldap&lt=%s"
loginUrl     = "https://login.hro.nl/v1/login"

where %s are filled in credentials

req, err := client.Post(loginUrl, "application/x-www-form-urlencoded", strings.NewReader(uri))

I'm getting as response that the Form cannot be resubmitted.

But when I try it with Postman rest client, I'm allowed to login.

code for Csrf token:

func getCSRFtoken() (key string) {
    doc, err := goquery.NewDocument(loginUrl)
    if err != nil {
        log.Fatal(err)
    }
    types := doc.Find("input")
    for node := range types.Nodes {
        singlething := types.Eq(node)

        hidden_input, _ := singlething.Attr("type")

        if hidden_input == "hidden" {
            key, _ := singlething.Attr("value")
            return key
        }
    }
    return ""
}

goquery.NewDocument is a http.Get()

My question now is, how does the URL get's formatted from the library

  • 写回答

1条回答 默认 最新

  • dongxingqiu7943 2016-04-01 16:50
    关注

    Maybe you would be better off using: (c *Client)PostForm(url string, data url.Values) (resp *Response, err error)

    from net/http like http://play.golang.org/p/8D6XI6arkz

    With the params in url.Values (instead of concatenating the strings, like you are doing now.)

    评论

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?