go-resty / resty

Simple HTTP and REST client library for Go
MIT License
9.89k stars 696 forks source link

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

Closed icepie closed 10 months ago

icepie commented 11 months ago

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 !

SVilgelm commented 11 months ago

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

r.SetContentLength(true)
icepie commented 10 months ago

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.

jeevatkm commented 10 months ago

Merged #730