August 2011

1 articles in August 2011

I’m starting to dive deep into Android world. The first step is usually the hardest. I’m starting to grasp how the Android environment operates. The best way for me to learn is by reading, and actually doing it. So, I started to build a room reservation app using an web service API built by my co-worker. Calling this API requires HTTP POST call from Android. This is where it gets interesting. I tried scouring the web for hours, and all the example I found did not work! I finally looked into android documentation, which is really where I should started first. It seems so simple. I could do it in 10 seconds in c#. However during my trial, all the post parameters are not recognized by the API, which is written using PHP. I’ll describe some of the mistake I made.

//import these on your header

import java.io.IOException;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.ProtocolException;
import java.net.URL;
import java.net.URLEncoder;
import java.util.Scanner;

//do this wherever you are wanting to POST
URL url;
HttpURLConnection conn; Continue Reading →