PostForm之后的301状态代码

时间:2016-09-12 19:54:41

标签: http go httpclient

我正在尝试编写一个程序,它将登录ahrefs.com并解析一些数据。 我首先向ahrefs.com发送GET请求以获取cookie和html来解析所需的令牌:

    client := &http.Client{}
    jar := &myjar{}
    jar.jar = make(map[string] []*http.Cookie)
    client.Jar = jar
    resp, _ := client.Get("https://ahrefs.com")

    root, _ := html.Parse(resp.Body)
    element, _ := getElementByName("_token", root)
    token := ""
    for _, a := range element.Attr {
        if a.Key == "value" {
            token = a.Val
        }
    }

然后我使用PostFormahrefs.com/user/login/发送POST请求。我用正确的数据填充字段(通过浏览器测试)。当我在浏览器中提交表单时,它的字段return_to具有站点主页的值,应该重定向到ahrefs.com/dashboard/metrics/(我要解析数据的页面)。但我的节目的行为是不同的。在PostForm 301后,我获得了resp, _ = client.PostForm( "https://ahrefs.com/user/login/", url.Values{ "email": {"djviman@gmail.com"}, "password": {"Aau4bqRxfc4ZEvu"}, "_token": {token}, "return_to": {"https://ahrefs.com/"}, }) log.Println(resp.Status) resp.Body.Close() 状态代码:

ahrefs.com/dashboard/metrics/

然后我向resp, _ = client.Get("https://ahrefs.com/") log.Println(resp.Status) resp.Body.Close() 发送GET请求,但它将我重定向到主页,就像我没有登录一样:

18:47:26.079 [main] ERROR o.s.boot.SpringApplication - Application startup faile
d org.springframework.context.ApplicationContextException: Unable to start embedde
d container; nested exception is org.springframework.context.ApplicationContextE
xception: Unable to start EmbeddedWebApplicationContext due to missing EmbeddedS
ervletContainerFactory bean.
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.onRefresh(EmbeddedWebApplicationContext.java:135) ~[ClientsIm.jar:na]
        at org.springframework.context.support.AbstractApplicationContext.refres
h(AbstractApplicationContext.java:476) ~[ClientsIm.jar:na]
        at org.springframework.boot.context.embedded.EmbeddedWebApplicationConte
xt.refresh(EmbeddedWebApplicationContext.java:120) ~[ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.refresh(SpringApplication.
java:691) [ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
:320) [ClientsIm.jar:na]
        at org.springframework.boot.SpringApplication.run(SpringApplication.java
:952) [ClientsIm.jar:na]
        at com.clientsim.server.Application.main(Application.java:13) [ClientsIm
.jar:na]
Caused by: org.springframework.context.ApplicationContextException: Unable to st
art EmbeddedWebApplicationContext due to missing EmbeddedServletContainerFactory
 bean.

问题是:我做错了什么?并且热门成功登录此站点?

0 个答案:

没有答案