bogdanfinn / tls-client

net/http.Client like HTTP Client with options to select specific client TLS Fingerprints to use for requests.
BSD 4-Clause "Original" or "Old" License
834 stars 163 forks source link

get response error with long url(redirect) #11

Closed magdev2022 closed 1 year ago

magdev2022 commented 2 years ago

Hello, I tried to get response by using tls-client. Request url is "https://www.mistore.jp/shopping/login". when access this url, request is redirected. redirect url is long like this.

https://login.api.mistore.jp/auth/realms/BB/protocol/openid-connect/auth?client_id=VS-API&redirect_uri=https://www.mistore.jp/on/demandware.store/Sites-seamless-Site/ja_JP/Login-OAuthReentryRX&response_type=code&state=1529753980&scope=openid&registration_uri=https%3A%2F%2Flogin.api.mistore.jp%2Fauth%2Frealms%2FBB%2Fprotocol%2Fopenid-connect%2Fauth%3Fclient_id%3DVS-API%26kc_action%3DEXT_ENTRY_CODE%26admsCd%3D2%26response_type%3Dcode%26scope%3Dopenid%26redirect_uri%3Dhttps%253A%252F%252Fwww.mipoint.jp%252Fmypage%252Fim%252Finfo%252Frp_member%252Fbpfregistpurchase%253FreturnUrl%253D%2526nextUrl%253Dhttps%253A%252F%252Fwww.mistore.jp%252Fshopping%252Fhome%253Frid%253D2714ec78a36f4acaba808373a39d822d%2526newMemberClass%253DWEB_PURCHASE_MEMBER

when redirect with this url, it seems to get wrong response. please let me know what is a problem. if try with standard http client, there is no problem.

bogdanfinn commented 2 years ago

@magdev2022

when redirect with this url, it seems to get wrong response.

What response are you receiving then?

func main() {
    jar, _ := cookiejar.New(nil)
    options := []tls_client.HttpClientOption{
        tls_client.WithTimeout(60),
        tls_client.WithClientProfile(tls_client.Chrome_105),
        tls_client.WithCookieJar(jar),
    }

    client, err := tls_client.NewHttpClient(tls_client.NewNoopLogger(), options...)

    u := "https://www.mistore.jp/shopping/login"
    req, err := http.NewRequest(http.MethodGet, u, nil)
    if err != nil {
        log.Println(err)
        return
    }

    req.Header = http.Header{
        "accept":          {"*/*"},
        "content-type":    {"text/html"},
        "accept-language": {"de-DE,de;q=0.9,en-US;q=0.8,en;q=0.7"},
        "user-agent":      {"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 Safari/537.36"},
        http.HeaderOrderKey: {
            "accept",
            "content-type",
            "accept-language",
            "user-agent",
        },
    }

    resp, err := client.Do(req)

    if err != nil {
        log.Println(err)
        return
    }

    defer resp.Body.Close()

    log.Println(fmt.Sprintf("GET (with redirect) %s : %d", u, resp.StatusCode))

    client.SetFollowRedirect(false)

    resp, err = client.Do(req)

    if err != nil {
        log.Println(err)
        return
    }

    defer resp.Body.Close()

    log.Println(fmt.Sprintf("GET (without redirect) %s : %d", u, resp.StatusCode))
}
2022/10/24 23:00:54 GET (with redirect) https://www.mistore.jp/shopping/login : 200
2022/10/24 23:01:05 GET (without redirect) https://www.mistore.jp/shopping/login : 302
bogdanfinn commented 2 years ago

@magdev2022 i assume this issue can be closed?

bogdanfinn commented 1 year ago

Closed due to inactivity. Please reopen if the issue is not solved.