B4J Question C# to B4X

Star-Dust

Expert
Licensed User
Longtime User
I should translate this little bit of code into b4X, and it seems very easy to do
B4X:
req = new RestRequest(Method.POST);
req.AddHeader("content-type", "application/json");
req.AddParameter("application/octet-stream", json, ParameterType.RequestBody);
I translated it like this
B4X:
client.Initialize("",Me)
client.PostString("https://xxx.xxx.xxx", "application/octet-stream=" & toJson)))
client.GetRequest.SetContentType("application/json")

But I get this error, as if the JSON format is wrong, but it is not because I have previously done the parsing. It seems to be related to the passing or serialization of the parameter and I assume it concerns the line reported in C #.
How could I correct?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Very strange way to send a json request.

1. Try to URLEncode the json string with StringUtils.
2. Set the content type to: application/x-www-form-urlencoded

0. Try this:
B4X:
client.Initialize("",Me)
client.PostString("https://xxx.xxx.xxx", toJson)
client.GetRequest.SetContentType("application/json")
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thank you. It is a particular request indeed. I'll try it today. I hadn't thought about encoding the JSON string like URLencode

It appears to require this content type: application/octet-stream
 
Upvote 0

TILogistic

Expert
Licensed User
Longtime User
this can give you an idea:


and:

 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Thanks, indefatigable error who reports to me is 500, character not recognized
 
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Your suggestion worked correctly
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…