Comments (5)
Thank you for:
- A package that simplified my code!
- Your quick reply to this issue!
- The link you provided to the desired feature!
I've encoded the solution proposed by the link but am unable to obtain the data for the unmarshalled object. Here's a code snippet:
type EntropyPost struct {
Session_id string `json:"session-id"`
Length uint `json:"length"`
Entropy []uint32 `json:"entropy"`
}
req := resty.R().
SetHeader("Content-Type", "application/json").
SetBody(body). // automatic conversion to json
SetResult(&EntropyPost{})
var resp *resty.Response
if resp, err = req.Post("http://172.17.0.2:8080/v1/316395C9-7226-41B2-94D7-013B778288FB/B615E471-CC76-4772-A879-3C865A131325/entropy/"); err != nil {
t.Fatal("Client get failed: " + err.Error())
}
fmt.Fprintln(os.Stderr, resp.Status())
var reply EntropyPost
if err := json.Unmarshal(resp.Body(), &reply); err != nil {
t.Fatal("Client unmarshal failed: " + err.Error())
}
fmt.Fprintf(os.Stderr, "reply: %v\n", reply)
fmt.Fprintf(os.Stderr, "Result(): %v\n", resp.Result().(*EntropyPost))
Here's the generated output:
200 OK
reply: {sessionId 128 [16909060 84281096 151653132 219025168]}
Result(): &{ 0 []}
The output demonstrates that a manual decoding of the json produces the expected result. However,
I must be missing something simple in the encoding of the SetResult & companion Result() that prevents the automatic unmarshalling to EntropyPost. I would appreciate your insight to identify the problem. Thanks!
from resty.
I believe you're referring this https://godoc.org/github.com/go-resty/resty#Request.SetResult
from resty.
Response automatic marshaling happens based on response Content-Type
header and Status Code.
Can you please enable debug resty.SetDebug(true)
in resty? and give me that details. It will help me to identify an issue.
from resty.
Again, thank you for you kind assistance! Using your suggestion of enabling SetDebug() method provided the information I needed to identify the problem. In this situation, the server's content type was set to plain text, not json.
Sorry to have had you remotely debug "my" problem.
from resty.
I'm happy for you, you're welcome.
from resty.
Related Issues (20)
- setTimeout does not take effect HOT 2
- memory leak when response is too large HOT 2
- SetRetryCount() on request? HOT 1
- It seems memory leaks with post HOT 3
- Call to http.DetectContentType has trailing NUL bytes in buffer HOT 1
- The SetContentLength(boo) method may cause an out-of-memory issue when uploading large files, such as 5GB. HOT 1
- CVE-2023-45286 HOT 3
- Breaks application from Ctrl-C handling HOT 1
- Brotli support HOT 1
- How to handle response if a call to API returns 200 with struct A, or 201 with struct B? HOT 3
- SetResult failed with httpmock HOT 2
- CVE-2023-45286: HTTP request body disclosure HOT 3
- SetProxy HOT 3
- The request with SetFileReader retry time great than 1 will has issues HOT 1
- Signing requests with path parameters HOT 1
- Clone or copy of existing client HOT 6
- cache middleware HOT 4
- retrying of non-idempotent methods HOT 2
- Path param encoding is broken
- can't use image.decode on rawbody HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from resty.