Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

框架中的劫持问题/Hijacking in the go-rod #492

Closed
lingyao2333 opened this issue Sep 30, 2021 · 3 comments
Closed

框架中的劫持问题/Hijacking in the go-rod #492

lingyao2333 opened this issue Sep 30, 2021 · 3 comments
Labels
question Questions related to rod

Comments

@lingyao2333
Copy link

router.MustAdd("/*", func(ctx *rod.Hijack) {
//开始设置标头
r := ctx.Request.SetContext(browser.GetContext())
rest := ctx.Request.Headers()
//设置body
STime := []SearchTime{{Start: "20210923", End: "20210924"}}
SearchFiltertr, err := json.Marshal(SearchFilter{D: STime})
if err != nil {
fmt.Println(err)
}
body := SearchCondition{Count: true, Filter: string(SearchFiltertr)}
fmt.Println("json")
bodystr, err := json.Marshal(body)
if err != nil {
fmt.Println(err)
}
fmt.Println(string(bodystr))
fmt.Println(r.Body())

	r.SetBody(body)
	ctx.Request.SetBody(body)

	ctx.MustLoadResponse()
	//t := &http.Transport{ForceAttemptHTTP2: true}
	//client := &http.Client{Transport: t}
	//ctx.LoadResponse(client, true)

	fmt.Println("ResponseCode: ")
	fmt.Println(ctx.Response.Payload().ResponseCode)

	resp := ctx.Response.Headers()

	fmt.Println("resp: ")
	fmt.Println(resp)
	respbody := ctx.Response.Body()
	fmt.Println("respbody")
	fmt.Println(respbody)

})

代码如上。此处运行时,在不修改任何数据的情况下。所有流程能走通。并且能获取到对应的request.body和response.body和对应的header。
但是一旦我设置了request.body。服务器返回的值则直接是错误。但是此处我打印过正常请求的格式和自行生成的格式,是一致的。所以想请问下怎么对request.body的修改
Code as above. Run here without modifying any data. All processes can go through. Body and Response. body and the corresponding header can be obtained.
But once I set request.body. The value returned by the server is an error. But here I printed the format of the normal request and the generated format is the same. So I would like to ask how to modify request.body

@lingyao2333 lingyao2333 added the question Questions related to rod label Sep 30, 2021
@rod-robot
Copy link

Please add a valid **Rod Version:** v0.0.0 to your issue. Current version is v0.101.8
generated by check-issue

@lingyao2333
Copy link
Author

go-rod版本为 v0.101.8

My go-rod version is v0.101.8

@ysmood
Copy link
Member

ysmood commented Sep 30, 2021

#322

@ysmood ysmood closed this as completed Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Questions related to rod
Projects
None yet
Development

No branches or pull requests

3 participants