I achieved what i was looking for through following code::
---------------------------------------START
package net.HttpDownload;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
import android.media.MediaRecorder.OutputFormat;
import android.net.Proxy;
//import android.net.*;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
public class HttpDownload extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Bitmap bitmap = DownloadImage("http://www.streetcar.org/mim/
cable/images/cable-01.jpg");
ImageView img = (ImageView) findViewById(R.id.img);
img.setImageBitmap(bitmap);
}
private InputStream OpenHttpConnection(String urlString)throws
IOException
{
Log.d("Narendra", "Inside ClientHttpRequest");
String posturl = "http://www.streetcar.org/mim/cable/images/
cable-01.jpg";
String agent = "Mozilla/4.0";
String type = "application/x-www-form-urlencoded";
HttpResponse response;
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(posturl);
httpost.addHeader("Content-Type", type);
httpost.addHeader("User-Agent", agent);
InputStream in = null;
String host = Proxy.getHost(this);
if (host != null)
{
HttpHost proxy = null;
int port = Proxy.getPort(this);
if (port > 0)
{
proxy = new HttpHost(host, port);
}
HttpParams params = new BasicHttpParams();
// HttpHost proxy = new HttpHost("172.24.1.17", 8080);
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
httpclient.setParams(params);
response=httpclient.execute(httpost);
in = response.getEntity().getContent();
//return in;
}
return in;
}
private Bitmap DownloadImage(String URL)
{
Bitmap bitmap = null;
InputStream in = null;
try {
in = OpenHttpConnection(URL);
bitmap = BitmapFactory.decodeStream(in);
in.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return bitmap;
}
}
---------------------------------------END
This may help others
THANX
On Jul 20, 1:01 pm, Peli <[email protected]> wrote:
> Which code did you try? The link contains several Java code examples
> withHTTPand POST.
>
> The more specific your question is, the better people can help you
> here. Please post a piece of code here that you tried but did not
> work, and we may be able to tell you what you need to change.
>
> Also, this does not sound like a very Android-specific question, so
> you may have more luck in a general Java-forum for beginners.
>
> Peliwww.openintents.org
>
> On Jul 20, 8:25 am, Chris <[email protected]> wrote:
>
>
>
> > It didnt help me......
>
> > Thanks
>
> > On Jul 17, 6:59 pm, Peli <[email protected]> wrote:
>
> > > Why don't you simply try a Google
> > > search?http://www.google.com/search?q=http+post+java
>
> > > Peliwww.openintents.org
>
> > > On Jul 17, 3:52 pm, Chris <[email protected]> wrote:
>
> > > > How to create anHTTPrequestobject of POST type in android? Which
> > > > class need to be extend or what method need to implement? How to
> > > > establish connection to a server?
> > > > Actually i want to connect to a microsoft exchange server, and then i
> > > > have to send arequestto it usingHTTP.
> > > > I dont have any idea about this, any help will be highly apperciated.
>
> > > > THANKS A LOT....- Hide quoted text -
>
> > > - Show quoted text -- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---