Need to append a string in DoPost method using andoid

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

Need to append a string in DoPost method using andoid

Postby suhabb » Mon Jan 04, 2010 5:43 am

I need to append a string to the URL in doPost method and sent it to server.

public void postData(){


// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://URL:8080/ActionServlet");

try {
// Add your data
// List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1);
// nameValuePairs.add(new BasicNameValuePair("mydata", "Mek Mek"));
String s="c1cf502a9441c48e7ee98f32d1d64413:c1cf502a9441c48e7ee98f32d1d64413";
httppost.setEntity(new StringEntity(s)); //i need to append the string something like this and send it to the srver.

BasicHttpResponse response = (BasicHttpResponse) httpclient
.execute(httppost);


Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);

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);
}

Convert the Bytes read to a String.
text = new String(baf.toByteArray());
tv.setText(text);

} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
suhabb
Freshman
Freshman
 
Posts: 2
Joined: Wed Dec 23, 2009 10:56 am

Top

Postby jwei512 » Mon Jan 04, 2010 10:20 am

Try reading this?

http://thinkandroid.wordpress.com/2009/ ... post-call/

This is my little code snippet on how to do POST calls with params. Maybe you'll find it useful.
- jwei

http://thinkandroid.wordpress.com
Examples, Code, and Tutorials
jwei512
Senior Developer
Senior Developer
 
Posts: 135
Joined: Mon Jul 27, 2009 9:35 pm
Location: Palo Alto, CA

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 7 guests