-
-
Notifications
You must be signed in to change notification settings - Fork 9
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
POST with JSON string not working #16
Comments
Hi! Thank you for using this library! I just summarize your questions here with my inline reply.
No, you are supposed to use a type and let the library do the serialization in json for you.
You use it as I designed it as long as you use a variable path into your body field. The key is into this line. I understand your use case. I think in the meanwhile twincat supports array with variable length, but they will ever have a fixed size during the serialization and since there isn't nullable in twincat (yet?) the problem will probably ever persist. I think that programmers life could be hard enough also without the need to work with strings operation under twincat, but I can imagine that sometimes might be easier to fill in or put together a json instead of handling with structures. I think in this case the solution might be easy: whenever the software recognize a json in the body field (e.g. starting with How does it sound to you? Would that solve your problem? Best regards, |
Thank you so much for thoughtfully considering my use case!
Ah, that clears things up. I may have had the wrong expectations based on this line of the README and the comment on this line of the HttpClient. I misread the README as allowing Json string data, and misread the comment as allowing (Variable path) OR (Json data string).
I think you correctly pointed out the root issue here. My team is adding more complexity than is preferred to solve the problems that come with serializing/parsing JSON data with dynamic length arrays, working with that data in TwinCAT structures, and providing external REST APIs data in an expected format. It would be one thing to design a system around these TwinCAT limitations (letting the external API handle more of the complexity), but it is more difficult when the external REST API is not open to changes.
In my opinion, this solution would provide a nice option! However, do you think the JSON string would still be limited in length due to the limitations with the HttpClient usage of NT_StartProcess.COMNDLINE? If so, I'm not sure if this would solve the majority of our problems, as the variable length arrays could get quite long, and the JSON string may get truncated unexpectedly. Alternative Feature Suggestion 1What might solve the problem is if a user could define a sufficiently sized Do you think this feature is possible? If so, would it be difficult to implement? ExampleMAIN.TcPOU
GVL.TcGVL
Alternative Feature Suggestion 2My team has been experimenting with dynamic arrays on the heap as well. If support was added for serializing JSON array data from pointers to dynamic arrays, this could also be a solution. However, I suspect that this would be quite difficult. Body.TcDUT
MAIN.TcPOU
GVL.TcGVL
|
Thank you for your work on this awesome library!
Should we be able to pass JSON strings in the Body of a POST request? Am I not using the Client correctly?
Body := ''
) because my endpoint validates the request.Failing example with JSON string
MAIN.TcPOU
GVL.TcGVL
header.json
The .NET/C# endpoint responds to POST with 200 if it receives a valid request body
ExampleController.cs
Request.cs
Working example with variable path
MAIN.TcPOU
GVL.TcGVL
Body.TcDUT
header.json
Why do I care about using a JSON string if the variable path to a DUT is working ok?
In my working example above, the DUT contains a property of type
ARRAY[0..9] OF STRING
, a static array, but the REST API endpoint takes in a dynamic array of strings, expected to vary with each call. For this use case, it is preferred to send:instead of what the DUT deserializes to:
Passing a JSON string to the HttpClient Body would be a workaround for all requests with dynamic arrays that do not serialize appropriately.
The text was updated successfully, but these errors were encountered: