go-resty / resty

Simple HTTP and REST client library for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[BUG] DigestAuth with SetBody will be 'http: ContentLength=54 with Body length 0'

icepie opened this issue · comments

commented

Code

	req := c.HttpClient.R().
		SetDigestAuth("admin", "123456").
		SetHeader("Content-Type", "application/xml").
		SetBody(reqBody)

	resp, err := req.Put("/ISAPI/AccessControl/RemoteControL/door/1")

Out

2023/10/11 17:13:52  Put "http://192.168.0.51/ISAPI/AccessControl/RemoteControL/door/1": net/http: HTTP/1.x transport connection broken: http: ContentLength=54 with Body length 0

but GET method will be fine !

there is a special function to automatically set the content length, it will also set to 0 if needed:

r.SetContentLength(true)
commented

there is a special function to automatically set the content length, it will also set to 0 if needed:

r.SetContentLength(true)

Code

	req := c.HttpClient.R().SetDigestAuth(c.username, c.password).
		SetHeader("Content-Type", "application/xml").
		SetContentLength(true).
		SetBody(reqBody)

	resp, err := req.
		Put("/ISAPI/AccessControl/RemoteControL/door/1")

Out

 Put "http://192.168.0.51/ISAPI/AccessControl/RemoteControL/door/1": net/http: HTTP/1.x transport connection broken: http: ContentLength=54 with Body length 0

Same problem.