0

Im coding a RESTful API & Android client at the same time as I go and im currently working on pulling the users profile from the server. I feel like this should definitely be a get request being that im only pulling existing data and im not adding/editing anything to my database, but I do need a user_id param to be able to query for the appropriate profile. Can I send just one tiny little variable along with my HttpGet some how or am i supposed to use a HttpPost in this situation regardless?

ChuckKelly
  • 1,742
  • 5
  • 25
  • 54

2 Answers2

0

GET can support adding variables/parameters. For example you could make a Url that looks like this:

http://yourwebsite.com/script.php?user_id=19898424

Oleg Vaskevich
  • 12,444
  • 6
  • 63
  • 80
0

Android uses Apache's HTTPClient. So, copying their tutorial code:

public void sendStringTo(String remoteUrl, String myString) {
    DefaultHttpClient httpclient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(remoteUrl+"?string1="+myString);
    HttpResponse response1 = httpclient.execute(httpGet);

    // The underlying HTTP connection is still held by the response object 
    // to allow the response content to be streamed directly from the network socket. 
    // In order to ensure correct deallocation of system resources 
    // the user MUST either fully consume the response content  or abort request 
    // execution by calling HttpGet#releaseConnection().

    try {
        System.out.println(response1.getStatusLine());
        HttpEntity entity1 = response1.getEntity();
        // do something useful with the response body
        // and ensure it is fully consumed
        EntityUtils.consume(entity1);
    } finally {
        httpGet.releaseConnection();
    }
    return;
}
hd1
  • 33,938
  • 5
  • 80
  • 91