Fiddler surrounds JSON Response

I have a web service implemented in Go that returns a JSON structure from an external service. Upon returning the object, it looks like this:

{"otherServiceInfoList":[],"action... 

My Go web service just reads the JSON for the snippet:

 response, err := ioutil.ReadAll(resp.Body) 

and returns it to the client:

 w.Write(response) 

The response is displayed as-is in Postman, however, Fiddler both adds and adds the answer as follows:

 34ee {"otherServiceInfoList":[],"... 0 

Pay attention to the leading 34ee and trailing 0 .

Then they push me forward to convert the answer:

"The response is encrypted and may require decoding before verification."

Accepting the prompt removes the original JSON returned. Is Go a w.write method that uses extra characters, or is it specific to Fiddler?

By the way, before writing to the buffer, I set the following header:

 w.Header().Set("Content-Type", "application/json; charset=UTF-8") 
+4
source share
2 answers

You are dealing with a response. I'm not sure what the ultimate goal is, but there are several different options. The source itself says:

  // Body represents the response body. // // The http Client and Transport guarantee that Body is always // non-nil, even on responses without a body or responses with // a zero-length body. It is the caller responsibility to // close Body. // // The Body is automatically dechunked if the server replied // with a "chunked" Transfer-Encoding. Body io.ReadCloser 

So, for example, here; response, err := ioutil.ReadAll(resp.Body) , where you send the response from another service, you can fix this problem by letting the service that provided resp set the Transfer-Encoding header with the changed value, assuming you have access to this api. If you work only in this middle layer, you will have to cancel the answer yourself before writing it. If the request that you control in Fiddler does not have chunked Transfer-Encoding, just an addition, which may cause Fiddler to display it the same way you see it in Postman.

+1
source

This is an HTTP 1.1 response. The protocol will send the format:

 size-of-chunk-in-hex chunk ... 

A final block size of 0 means the end of the response. Your example shows that the answer is 13550 bytes, and is sent in one piece.

+2
source

All Articles