-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
How to set http client post method #202
Comments
You can easly req := fasthttp.AcquireRequest()
req.URI().Update("mysite.com/mypath")
req.Header.SetMethodBytes([]byte("PUT")) // or "DELETE"
res := fasthttp.AcquireResponse()
err := ClientFasthttp.Do(req, res)
//... check res.XXX methods for the response from mysite.com/mypath
// when finish
fasthttp.ReleaseRequest(req)
fasthttp.ReleaseResponse(res) Hope that helped you! |
When I use GET in this code,I can not get result from server ,and it returns tomcat error type Status report message Bad Content-Type header value: 'Accept-Encoding' description The request sent by the client was syntactically incorrect. The code is below
|
It is because I add Why |
GET http://127.0.0.1:8080/eureka/v2/apps/629d2b13-b144-4b4d-ba83-292b0d9a5a48 HTTP/1.1 Seems everything is fine ,If I don't set header,the request will be success,and the default Accept is xml,But I want Json response.I can get json response by net/http,But after I replace with fasthttp,it report 400 error |
I can get json response by below code package main import ( func main() {
} But I have to remove req.Header.Add("content-type", "application/json") in fasthttp to get right json response or it will report 400 status package main import ( func main() {
}
} |
Use net/http I got Json in right characters |
I found response header "Content-Encoding: gzip" So I unzip the body,the result is fine,But still have a problem Why I set header Content-type to application/json, tomcat report 400,but net/http is fine |
I print out the whole Request,the content-type is application/json,not Accept-Encoding GET /eureka/v2/apps/EUREKA HTTP/1.1 |
Seems both Content-Type and Accept,doesn't take affect to API /eureka/v2/apps/EUREKA But net/http doesn't have this issue to call eureka |
In net/http,I can declare request and set method use below
// NewRequest returns a new Request given a method, URL, and optional body.
//
// If the provided body is also an io.Closer, the returned
// Request.Body is set to body and will be closed by the Client
// methods Do, Post, and PostForm, and Transport.RoundTrip.
//
// NewRequest returns a Request suitable for use with Client.Do or
// Transport.RoundTrip.
// To create a request for use with testing a Server Handler use either
// ReadRequest or manually update the Request fields. See the Request
// type's documentation for the difference between inbound and outbound
// request fields.
func NewRequest(method, urlStr string, body io.Reader) (*Request, error)
and then use Do method to send request
But How to set method like "PUT" and "DELETE" in fasthttp.Request
The text was updated successfully, but these errors were encountered: