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

如果SetBody放在SetMethod的前面,请求时无body #395

Open
aeroplane opened this issue Jan 6, 2025 · 2 comments
Open

如果SetBody放在SetMethod的前面,请求时无body #395

aeroplane opened this issue Jan 6, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@aeroplane
Copy link

RequestUse 只是示例,真实代码中没有这个

错误的示例

gout.New().
WithContext(ctx).
SetTimeout(time.Second*100).
SetURL("http://xxxx").
SetBody("22222"). // 不能放在SetMethod的前面
SetMethod("POST").
RequestUse(middler.WithRequestMiddlerFunc(func(req *http.Request) error {
	bytes, _ := io.ReadAll(req.Body)  // 读取不到任何数据

	return nil
}))
Do();

正确的做法

gout.New().
WithContext(ctx).
SetTimeout(time.Second*100).
SetURL("http://xxxx").
SetMethod("POST").
SetBody("22222"). 
RequestUse(middler.WithRequestMiddlerFunc(func(req *http.Request) error {
	bytes, _ := io.ReadAll(req.Body)  // 可以读取到数据

	return nil
}))
Do();
@guonaihong guonaihong added the bug Something isn't working label Jan 6, 2025
@guonaihong
Copy link
Owner

guonaihong commented Jan 6, 2025

感谢发现了这个问题,看了下代码,是SetURL目前的实现会reset一些状态。
明天中午我改下。

@guonaihong guonaihong mentioned this issue Jan 7, 2025
@guonaihong
Copy link
Owner

试下master最新代码呢。提交了一个pr,如果没有问题,晚上回去打个tag。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants