Gamestudio Links
Zorro Links
Newest Posts
Blind Zorro Window
by Martin_HH. 09/11/26 08:01
Parent/child object
by 3run. 09/11/26 06:21
ZorroGPT
by TipmyPip. 09/09/26 14:35
[MED] Import from FBX (2010) missing!!!
by USER0328. 09/03/26 18:03
Purchase A8 full licence version
by ukgamer. 08/30/26 14:27
Retrieve optimize() variables order (edited)
by NorbertSz. 08/25/26 13:24
Max Number of Strategies in /Strategy folder
by Martin_HH. 08/17/26 07:54
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (3run, Martin_HH, shuhari), 3,308 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
speedx, liop, Bauer097, riggi89, shuhari
19233 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
http POST of JSON data to remote server #480471
06/08/20 16:08
06/08/20 16:08
Joined: May 2018
Posts: 138
S
SBGuy Offline OP
Member
SBGuy  Offline OP
Member
S

Joined: May 2018
Posts: 138
I'm trying to post a simple JSON to a remote server. The command line curl test works, but I can't seem to properly format my JSON string in the data variable for an http_post or http_send call. Any idea where my mistake is? I've tried both single quote and escaped double quotes.

Thanks!

Code
	string data = "{\
		\"apikey\":\"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\", \
		\"systemid\":\"129392723\", \
		\"signal\":{ \
			\"action\":\"BTO\", \
			\"quant\": 3, \
			\"symbol\":\"AAPL\", \
			\"typeofsymbol\":\"stock\", \
			\"market\": 1, \
			\"duration\":\"DAY\" \
		} \
	}";

	int id = http_post(URL, data);



*************** server response *********************

{
   "ok" : "0",
   "error" : {
      "title" : "Invalid JSON",
      "message" : "\"':' expected, at character offset 1 (before \\\"\\\\\\\\r\\\\n\\\\t\\\\t\\\"apikey\\\":\\\"6...\\\")\\n\""
   }
}


Last edited by SBGuy; 06/08/20 16:33.
Re: http POST of JSON data to remote server [Re: SBGuy] #480472
06/08/20 16:42
06/08/20 16:42
Joined: May 2018
Posts: 138
S
SBGuy Offline OP
Member
SBGuy  Offline OP
Member
S

Joined: May 2018
Posts: 138
Solved!!! Apparently the line continuation backslash is the problem.

I supposed if I used some json library I wouldn't have this problem, but it was a simple POST so I didn't bother.

Re: http POST of JSON data to remote server [Re: SBGuy] #480474
06/08/20 17:38
06/08/20 17:38
Joined: May 2020
Posts: 9
Ireland
O
onoff Offline
Newbie
onoff  Offline
Newbie
O

Joined: May 2020
Posts: 9
Ireland
I highly recommend Postman for building and testing remote calls to APIs and whatnot...

Re: http POST of JSON data to remote server [Re: SBGuy] #480475
06/08/20 17:47
06/08/20 17:47
Joined: Feb 2017
Posts: 1,830
Chicago
AndrewAMD Offline
Serious User
AndrewAMD  Offline
Serious User

Joined: Feb 2017
Posts: 1,830
Chicago
Originally Posted by SBGuy
I supposed if I used some json library I wouldn't have this problem, but it was a simple POST so I didn't bother.
Generating json from scratch is easy. It's parsing json which is a bit more tedious and might justify the use of a library.

In my blog, I use jsmn as a library to parse json in Zorro:
https://www.vitaltrades.com/2019/01...sing-zorro-script-part-2-parse-any-json/

You also have the option of loading a json file directly so that you don't have to intermix C and json so much.


Moderated by  Petra 

Powered by UBB.threads™ PHP Forum Software 7.7.1