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

digest认证,获取body为nil,怎么能获取到数据 #344

Open
supersndqd opened this issue Apr 10, 2024 · 10 comments
Open

digest认证,获取body为nil,怎么能获取到数据 #344

supersndqd opened this issue Apr 10, 2024 · 10 comments

Comments

@supersndqd
Copy link

supersndqd commented Apr 10, 2024

resp, err := client.R().
	SetDigestAuth("name”."password”).
	SetBodyJsonMarshal(&Register).
	SetSuccessResult(&rkBack).
	Post("http://1.1.1.1/Register")

rkBack 为nil
实际抓包,是有数据返回的

@imroc
Copy link
Owner

imroc commented Apr 10, 2024

检查下 err 是否为 nil,也开下 DevMode看看实际返回的跟rkBack结构是否一致

@supersndqd
Copy link
Author

supersndqd commented Apr 10, 2024

err不为nil,err的判断里面我加了continue,后面代码继续在跑,而且statuscode是200,也是成功,就是resp.body是空的
rkBack是struct的默认值,resp判断是nil
DevMode 同样无法同样无法看到resp的内容

@supersndqd
Copy link
Author

我开始用body一个int值作判断的,0就是成功,跑了好多天了,才发现这个问题

@imroc
Copy link
Owner

imroc commented Apr 10, 2024

判断 err 是基础操作,如果不为 nil 一定要报出来方便排查

@supersndqd
Copy link
Author

说错,err为nil
我做了判断
if err != nil {
fmt.Println("reg", err)
time.Sleep(3 * time.Second)
registerch <- 1
continue
}
程序继续往下执行了

@supersndqd
Copy link
Author

digest两次连接,我感觉resp保留的是第一次401的空body,想看源代码,几次跳转.放弃,跟大佬求助

@imroc
Copy link
Owner

imroc commented Apr 10, 2024

digest两次连接,我感觉resp保留的是第一次401的空body,想看源代码,几次跳转.放弃,跟大佬求助

能否给可复现的代码,如不方便公开可发我邮箱 [email protected]

@supersndqd
Copy link
Author

qq邮箱,已经发送

@norlight
Copy link

op解决了吗?同样的问题,首次请求成功最终拿到的resp是空的,抓包数据正常。(首次请求内部分为2步,401+200)。
第二次以及之后的每一次请求则都能成功,resp正常有数据的。(Connection: keep-alive,请求内部只有一步,不再有401,直接是200)。

@supersndqd
Copy link
Author

因为我的应用比较简单,就是简单restful,除了一个digest认证,目前用原始net/http了,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants