Android: Posting a httppost to php localhost server?

Gireesh

New member
I am trying to create an app that acts as a front end to my joomla component of php. This is actually GPS based app. All i have to post in the http is username, latitude, longitude. I could successfully fetch the latitude and longitude but could not post it to the server. Sorry its huge. plz be patient...
Here is my code:
/*My remaining code works well. so i am sending u only the http part*/
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://localhost:80/demo/index.php");

try {
// Add your data
List nameValuePairs = new ArrayList(6);
nameValuePairs.add(new BasicNameValuePair("option", "com_geoinformation"));
nameValuePairs.add(new BasicNameValuePair("tmpl", "component"));
nameValuePairs.add(new BasicNameValuePair("task", "geoinformation.getInformation"));
nameValuePairs.add(new BasicNameValuePair("username", username));
nameValuePairs.add(new BasicNameValuePair("latitude", String.valueOf(latitude)));
nameValuePairs.add(new BasicNameValuePair("longitude", String.valueOf(longitude)));


httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));


// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
int status = response.getStatusLine().getStatusCode();
InputStream is = response.getEntity().getContent();

BufferedInputStream bis = new BufferedInputStream(is);

ByteArrayBuffer baf = new ByteArrayBuffer(20);

int current = 0;

while((current = bis.read()) != -1){
baf.append((byte)current);
}



Toast.makeText(LatlongActivity.this,String.valueOf(baf.toByteArray()) , Toast.LENGTH_LONG).show();
} catch (ClientProtocolException e) {

} catch (IOException e) {

}
}
});

Manifest file:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission><uses-permission android:name="android.permission.INTERNET"></uses-permission>

.
It shows warning that List is a raw type and should be parametrized. And i have no errors... Plz solve it asap
 
Back
Top