I need to send something via http request like this:
http://emoncms.org/input/post.json?json ... ba34gh3456
I can build the expression no problem, but where I'm having trouble is the curly braces. I can build the expression as a variable or the contents of a file. The emoncms input requires them, and Automagic keeps trying to interpret them. I have read through the forums and looked for help already. This thread was useful:
http://automagic4android.com/forum/view ... f=5&t=2544
I've tried all kinds of combinations of quote marks, etc, but I still can't make it work.
Any suggestions?
Thanks
Problem using curly brace { in a json string as http request
Moderator: Martin
Re: Problem using curly brace { in a json string as http req
You can use the + operator in a script to compose the URL. I recommend to create the JSON-text in an action script:
URL in action HTTP Request:
http://emoncms.org/input/post.json?json ... ba34gh3456
The Android libraries to handle URLs are very strict so above URL will not work because Android does not accept the {-character of the JSON text in the query part of the URL. Special characters need to be escaped with the encodeURL-function:
http://emoncms.org/input/post.json?json ... ba34gh3456
This will also encode all other special characters that might be contained in the variables embedded in the JSON string.
Theoretically you could also create the URL in an inline script directly in action HTTP Request (it's not very readable in this case):
http://emoncms.org/input/post.json?json={encodeURL('{var1:' + variable1 + ',var2:' + variable2 + '}')}&apikey=beshytb5fd0633c8d7d24dba34gh3456
Regards,
Martin
Code: Select all
variable1="text1";
variable2="text2";
json = '{var1:' + variable1 + ',var2:' + variable2 + '}';
http://emoncms.org/input/post.json?json ... ba34gh3456
The Android libraries to handle URLs are very strict so above URL will not work because Android does not accept the {-character of the JSON text in the query part of the URL. Special characters need to be escaped with the encodeURL-function:
http://emoncms.org/input/post.json?json ... ba34gh3456
This will also encode all other special characters that might be contained in the variables embedded in the JSON string.
Theoretically you could also create the URL in an inline script directly in action HTTP Request (it's not very readable in this case):
http://emoncms.org/input/post.json?json={encodeURL('{var1:' + variable1 + ',var2:' + variable2 + '}')}&apikey=beshytb5fd0633c8d7d24dba34gh3456
Regards,
Martin
Re: Problem using curly brace { in a json string as http req
Martin,
Thank you VERY much!!!
I followed your instructions to the letter and it now works perfectly.
Thanks again.
Thank you VERY much!!!
I followed your instructions to the letter and it now works perfectly.
Thanks again.