Created
February 12, 2013 14:41
-
-
Save donv/4770295 to your computer and use it in GitHub Desktop.
Ruboto Android POST example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
java_import 'android.net.http.AndroidHttpClient' | |
java_import 'android.util.Log' | |
java_import 'org.apache.http.client.entity.UrlEncodedFormEntity' | |
java_import 'org.apache.http.client.methods.HttpPost' | |
java_import 'org.apache.http.message.BasicNameValuePair' | |
java_import 'org.apache.http.util.EntityUtils' | |
t = Thread.start do | |
begin | |
client = AndroidHttpClient.newInstance('MyClient') | |
method = HttpPost.new("http://example.com/orders/create") | |
method.setHeader("Content-Type", "application/x-www-form-urlencoded"); | |
list = [BasicNameValuePair.new('order[amount]', '42'), BasicNameValuePair.new('order[product_id]', '37')] | |
entity = UrlEncodedFormEntity.new(list) | |
method.setEntity(entity) | |
response = EntityUtils.toString(client.execute(method).entity) | |
rescue Exception | |
Log.i 'MyApp', "Exception in task:\n#$!\n#{$!.backtrace.join("\n")}" | |
ensure | |
client.close if client | |
end | |
end | |
t.join |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment