Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / How to send a JSON object via SendHTTPRequest in Tier 1?

Author
Message
Space Dream Studios
Competition Prize Winner 2014
14
Years of Service
User Offline
Joined: 3rd Mar 2010
Location:
Posted: 9th Oct 2014 16:16 Edited at: 9th Oct 2014 18:06
I'm working on a solar plant management app. Everything works fine so far. But now I have to connect the app with the webbox of the plant via the internet. The webbox provides a server which could be accessed by http requests, encoded in JSON format. I'm totally new to the JSON subject and don't know how to construct the correct SendHTTPRequest in AGK.

The official call to request basic plant data is following JSON object (regarding webbox manufacturer documentation):



I also have the IP address of the plant and the folder to send the request:

It's something like: http://IPaddress/rpc

I tried different ways of writing the data into the POST field of the SendHTTPRequest function, but without any success. Actually no error message from the server too. Just an empty result string, instead of any plant data.

EDIT: Don't know, but it's may be basically not possible to send a JSON "object" with the SendHTTPRequest? May be I should send the raw data to an PHP file and make the request from there on? If yes, how to do that?

Hope one of you guys could help me out.
Thanks a lot in advance!

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Oct 2014 17:38
hmm, i would say its this

chr(34) = "

json$="RPC={"+chr(34)+"version"+chr(34)+": "+chr(34)+"1.0"+chr(34)+","+chr(34)+"proc"+chr(34)+": "+chr(34)+"GetPlantOverview"+chr(34)+","+chr(34)+"id"+chr(34)+": "+chr(34)+"1"+chr(34)+","+chr(34)+"format"+chr(34)+": "+chr(34)+"JSON"+chr(34)+"+chr(34)+"}"

SendHTTPRequest("IP","rpc",json$)

http://json.org/
http://www.appgamekit.com/documentation/Reference/HTTP/SendHTTPRequest.htm

AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265
Space Dream Studios
Competition Prize Winner 2014
14
Years of Service
User Offline
Joined: 3rd Mar 2010
Location:
Posted: 9th Oct 2014 18:03
@Markus: Thanks, but that's not working too, unfortunately. No result from Server back....

BMacZero
18
Years of Service
User Offline
Joined: 30th Dec 2005
Location: E:/ NA / USA
Posted: 9th Oct 2014 18:33 Edited at: 9th Oct 2014 18:36
You may need to URL-encode the JSON, the HTTP protocol might not be happy with all the special characters in it.

Also note that the "RPC=" is not part of the JSON - that's a key that will contain the JSON data in the HTTP request.



You could also try sending it via GET rather than post, though POST seems like the better option:



Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 9th Oct 2014 19:06 Edited at: 9th Oct 2014 19:09
i think rpc was double, means json begin with {
then rpc is part of url get http://server/?rpc=blah

did u try this?




AGK 108 (B)19 + AppGameKit V2 Alpha .. : Windows 8.1 Pro 64 Bit : AMD Radeon R7 265

Login to post a reply

Server time is: 2024-11-25 10:39:36
Your offset time is: 2024-11-25 10:39:36