Http PUT AND POST REQUEST IN APP INVENTOR

5,754 views
Skip to first unread message

jayakar...@gmail.com

unread,
Feb 5, 2014, 11:53:16 PM2/5/14
to mitappinv...@googlegroups.com
Please SEARCH in this forum before posting your question.   There's a good chance your question has already been asked.

If you are asking for technical help, you must provide the following information:
- Are you using MIT App Inventor Classic, MIT App Inventor 2, or something else (what?)
- What OS are you using? (e.g, MacOS 1.8, Windows 8, ...)
- What browser are you using (e.g, Chrome version 30, Firefox 24, IE 8, ...)
Also provide as much information as you can, such as screenshots and instructions that will let others duplicate the issue.

How can I make a http POST AND PUT REQUEST IN AppInventor2?

I am working with a webinterface, I tested the Post and Put request using Python using the code given bellow:

>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()

http://docs.python.org/2/library/httplib.html

I would like to know how the same thing can be done from an App developed using appinventor. The most important thing in this is I have to add params. And the python code also works when I modify the conn.request to conn.request("PUT", "", params, headers)

I hope anyone can help me in building an App Using appinventor which does the same work the python code does.

Josh @ MIT

unread,
Feb 6, 2014, 7:33:26 AM2/6/14
to mitappinv...@googlegroups.com, jayakar...@gmail.com
Hi there,

You should probably try using the "Web" component, which is a non-visible component in the "Connectivity" bin of the designer window.

For more information on what this allows, see the documentation at:

Good luck,
Josh

jayakar...@gmail.com

unread,
Feb 8, 2014, 12:02:39 PM2/8/14
to mitappinv...@googlegroups.com, jayakar...@gmail.com
Thanks for the reply, I tried the web component, I am able to use the HTTP GET and get the response from the server. But when I have to use the PUT request, I need a data structure similar to dictionary available in python which is mentioned here: http://stackoverflow.com/questions/9197324/curly-braces-in-python-in-2012

I would like to know weather I can use the list or TinyDB for making a similar data structure. If yes, how?

fturbak

unread,
Feb 8, 2014, 12:22:41 PM2/8/14
to mitappinv...@googlegroups.com, jayakar...@gmail.com
App Inventor does not currently have a Python-like dictionary data structure, but we are working on adding one. However, it could be quite a while before this feature is released. 

In the meantime, there are still various things you can do in App Inventor to handle dictionary-like data:
  • Many Web APIs return data in JSON format, which is just a string notation for trees formed out of lists and dictionaries whose leaves are things like numbers and strings.  You can use the Web component's JsonTextDecode method to convert JSON strings to App Inventor list structure in which the JSON dictionaries (i.e., comma separated key/value pairs delimited by braces) are converted to  so-called association lists (lists of key/value pairs, where such a pair is just a list of two elements = the key and the value) in App Inventor. For an example of this, see my recent response in the Forum thread titled "Getting data from google maps API". 
  • Many Web APIs require you to submit information in the form of key/value pairs. Typically this is done via request headers, which are handled in App Inventor by using the Set RequestHeader block with an argument value that's an association list of key/value pairs. But some Web APIs require information to be submitted in JSON format. In this case, you would need to write code that converted the key/value pairs into strings using JSON dictionary format like "{key1:value1, key2:value2, ....}". This will become much less cumbersome when App Inventor supports dictionaries directly.
- lyn - 
Message has been deleted

jayakar...@gmail.com

unread,
Feb 8, 2014, 12:37:09 PM2/8/14
to mitappinv...@googlegroups.com, jayakar...@gmail.com
Thanks Franklyn,

JSON DECODE DID THE WORK.
Reply all
Reply to author
Forward
0 new messages