Did you try configuring emulator proxy connection as discussed below:
http://groups.google.com/group/android-developers/browse_thread/thread/5bf421494daf6784/2cc9564fd9f62e37
On Fri, Aug 22, 2008 at 1:51 AM, Graeme <[EMAIL PROTECTED]> wrote:
>
> hi sacoskun
>
> Thanks for your suggestion. Yes I had not set the INTERNET permission
> in my
> AndroidManifest.xml. I have updated that now and the socket exception
> has changed
> to being about being unable to resolve the domain name of a http proxy
> server
> I am located behind. I have noticed other threads where http-proxy
> usage has been
> problematic.
>
> Thanks for your tip.
> Best Regards
> Graeme
>
> On Aug 22, 7:30 am, sacoskun <[EMAIL PROTECTED]> wrote:
> > Did you add <uses-permission
> > android:name="android.permission.INTERNET" /> tag to your
> > AndroidManifest.xml?
> > The new SDK requires that permission for network calls.
> >
> > sacoskun
> >
> > On Aug 21, 6:13 pm, Graeme <[EMAIL PROTECTED]> wrote:
> >
> >
> >
> > > Hi everyone
> >
> > > I'm trying to figure out how to use HttpClient 4.x to do POST requests
> > > routed via
> > > a Proxy server. I'm seeing a socket exception triggered by calling
> >
> > > DefaultHttpClient.execute(HttpHost target, HttpRequest method). My
> > > HttpPoster class looks like
> >
> > > package com.bt.gcto.android.testhttp;
> >
> > > import java.io.IOException;
> > > import java.util.Hashtable;
> >
> > > import org.apache.http.Header;
> > > import org.apache.http.HttpEntity;
> > > import org.apache.http.HttpHost;
> > > import org.apache.http.HttpResponse;
> > > import org.apache.http.HttpVersion;
> > > import org.apache.http.client.HttpClient;
> > > import org.apache.http.client.methods.HttpPost;
> > > import org.apache.http.conn.ClientConnectionManager;
> > > import org.apache.http.conn.params.ConnRoutePNames;
> > > import org.apache.http.conn.scheme.PlainSocketFactory;
> > > import org.apache.http.conn.scheme.Scheme;
> > > import org.apache.http.conn.scheme.SchemeRegistry;
> > > import org.apache.http.conn.scheme.SocketFactory;
> > > import org.apache.http.conn.ssl.SSLSocketFactory;
> > > import org.apache.http.impl.client.DefaultHttpClient;
> > > import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
> > > import org.apache.http.params.BasicHttpParams;
> > > import org.apache.http.params.HttpParams;
> > > import org.apache.http.params.HttpProtocolParams;
> > > import org.apache.http.util.EntityUtils;
> >
> > > import android.net.Uri;
> > > import android.util.Log;
> >
> > > public class HttpPoster {
> > > private final String TAG="HttpPoster";
> > > private final String NETWORK_DEVICE_SIDE_TRUE =
> > > ";deviceside=true";
> > > private final String NETWORK_DEVICE_SIDE_FALSE =
> > > ";deviceside=false";
> > > private final String NETWORK_WIFI = ";interface=wifi";
> > > //private final String proxy="proxy.intra.bt.com:8080";
> > > private boolean useWifi;
> > > private boolean deviceSide;
> > > // Apache HttpClient 4.x stuff
> > > private static HttpParams defaultParameters = null;
> > > private static SchemeRegistry supportedSchemes = null;
> >
> > > /**
> > > * Performs general setup.
> > > * This should be called only once.
> > > */
> > > private final static void setup() {
> >
> > > supportedSchemes = new SchemeRegistry();
> >
> > > // Register the "http" and "https" protocol schemes,
> they are
> > > // required by the default operator to look up socket
> > > factories.
> > > SocketFactory sf =
> PlainSocketFactory.getSocketFactory();
> > > supportedSchemes.register(new Scheme("http", sf, 80));
> > > sf = SSLSocketFactory.getSocketFactory();
> > > supportedSchemes.register(new Scheme("https", sf, 80));
> >
> > > // prepare parameters
> > > HttpParams params = new BasicHttpParams();
> > > HttpProtocolParams.setVersion(params,
> HttpVersion.HTTP_1_1);
> > > HttpProtocolParams.setContentCharset(params, "UTF-8");
> > > HttpProtocolParams.setUseExpectContinue(params, true);
> > > defaultParameters = params;
> >
> > > } // setup
> >
> > > private final static HttpParams getParams() {
> > > return defaultParameters;
> > > }
> >
> > > HttpPoster(boolean deviceSide, boolean useWifi) {
> > > this.useWifi = useWifi;
> > > this.deviceSide = deviceSide;
> > > System.err.println("HttpPoster::HttpPoster");
> > > }
> >
> > > public String post(String url,
> > >
> Hashtable<String,String> headerProperties, byte[] bytes )
> > > throws IOException {
> > > HttpClient client = null;
> > > HttpPost method=null;
> > > //InputStream is = null;
> > > //OutputStream os = null;
> > > //String response = "";
> > > HttpResponse rsp = null;
> > > HttpEntity entity=null;
> > > String fullUrl;
> > > //int rc;
> >
> > > Log.d(TAG,"post() ---ENTER---");
> > > Log.d(TAG,"HttpPoster::post");
> > > Log.d(TAG,"http.proxyHost = " +
> > > System.getProperty("http.proxyHost"));
> > > Log.d(TAG,"http.proxyPort = " +
> > > System.getProperty("http.proxyPort"));
> > > try {
> > > fullUrl = url + (deviceSide ?
> NETWORK_DEVICE_SIDE_TRUE :
> > > NETWORK_DEVICE_SIDE_FALSE)
> > > + (useWifi ? NETWORK_WIFI : "");
> > > Uri fullUri = Uri.parse( fullUrl );
> > > String targetname = fullUri.getHost();
> > > Log.d(TAG,"HttpPoster::post -- about to open
> connection
> > > on URL = " + fullUrl);
> > > //
> > > // setup proxy server
> > > //
> > > final HttpHost target = new
> HttpHost(targetname, 80,
> > > "http");
> > > final HttpHost proxy = new HttpHost("
> proxy.mycompany.com",
> > > 8080, "http");
> >
> > > setup() ; // Some general setup
> > > client = new DefaultHttpClient() ;
> >
> > > client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
> >
> > > method = new HttpPost( fullUrl );
> > > Log.d(TAG,"Executing request to " + target + "
> via " +
> > > proxy);
> > > rsp = client.execute(target, method);
> > > entity = rsp.getEntity();
> >
> > >
> Log.d(TAG,"---------------------------------------------");
> > > Log.d(TAG, rsp.getStatusLine().toString() );
> > > Header [] headers = rsp.getAllHeaders();
> > > for (int i=0; i<headers.length; i++) {
> > > Log.d(TAG,"\t" + headers[i] );
> > > }
> > >
> Log.d(TAG,"---------------------------------------------");
> >
> > > if (rsp.getEntity() != null) {
> > > Log.d(TAG, EntityUtils.toString(
> rsp.getEntity() ) );
> > > }
> > > } finally {
> > > if (entity != null)
> > > entity.consumeContent(); // release
> connection gracefully
> > > }
> > > // return response;
> > > Log.d(TAG,"post() ---EXIT---");
> > > return new String("");
> > > }
> >
> > > private final static HttpClient createHttpClient() {
> >
> > > ClientConnectionManager ccm =
> > > new ThreadSafeClientConnManager(getParams(),
> > > supportedSchemes);
> > > // new SingleClientConnManager(getParams(),
> > > supportedSchemes);
> >
> > > DefaultHttpClient dhc =
> > > new DefaultHttpClient(ccm, getParams());
> >
> > > return dhc;
> > > }
> >
> > > }
> >
> > > My TestHttp application launches an Activity TestHttp::onCreate()
> > > method whose DDMS logcat output is
> >
> > > 08-21 14:25:54.189: DEBUG/TestHttp(238): onCreate()---enter---
> > > 08-21 14:25:54.248: DEBUG/TestHttp(238): httpClient is non-null
> > > 08-21 14:25:54.398: DEBUG/TestHttp(238): in catch {} response is null
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): Error
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): java.net.SocketException:
> > > unknown error
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.harmony.luni.platform.OSNetworkSystem.createSocketImpl(Native
> > > Method)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.harmony.luni.platform.OSNetworkSystem.createSocket(OSNetworkSystem.java:
> > > 79)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.harmony.luni.net.PlainSocketImpl2.create(PlainSocketImpl2.java:
> > > 59)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > > java.net.Socket.checkClosedAndCreate(Socket.java:763)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > > java.net.Socket.connect(Socket.java:910)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:
> > > 117)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:
> > > 129)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:
> > > 164)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> > >
> org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:
> > > 119)
> > > 08-21 14:25:54.418: ERROR/TestHttp(238): at
> >
> > ...
> >
> > read more »- 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]
Announcing the new Android 0.9 SDK beta!
http://android-developers.blogspot.com/2008/08/announcing-beta-release-of-android-sdk.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---