Get Input String from an Url

Quickly share your Android Code Snippets here...

Get Input String from an Url

Postby pedroteixeira07 » Thu May 13, 2010 5:04 pm

Hi there, I have this snippet of code that allows me to POST into a file by using the URL and I retrieve the InputStream... Can anyone help me to allow posting an Array of strings also, instead of just a BasicNameValuePair? Thank you in advance


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. public static InputStream getInputStreamFromUrl(String url) {
  3.  
  4.                 InputStream content = null;
  5.  
  6.                 try {
  7.  
  8.                         HttpClient httpclient = new DefaultHttpClient();
  9.  
  10.                         HttpPost httpPost = new HttpPost(url);
  11.  
  12.                         List nameValuePairs = new ArrayList(1);
  13.  
  14.                         //this is where you add your data to the post method
  15.  
  16.                         nameValuePairs.add(new BasicNameValuePair(
  17.  
  18.                         "name", "anthony"));
  19.  
  20.                         httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  21.  
  22.                         // Execute HTTP Post Request
  23.  
  24.                         HttpResponse response = httpclient.execute(httpPost);
  25.  
  26.                         content = response.getEntity().getContent();
  27.  
  28.                         return content;
  29.  
  30.                 }
  31.  
  32. }
  33.  
  34.  
Parsed in 0.035 seconds, using GeSHi 1.0.8.4
pedroteixeira07
Experienced Developer
Experienced Developer
 
Posts: 74
Joined: Sun Oct 18, 2009 6:06 pm
Location: Funchal

Top

Return to Code Snippets for Android

Who is online

Users browsing this forum: No registered users and 6 guests