There is no reason why it should not work for a service. Do you see anything
in the Logcat? Are you sure it's a timeout? Can  you post the stack trace?

On Sat, Nov 6, 2010 at 7:08 AM, Burk Ferden <[email protected]>wrote:

> Hello,
> I am trying to do a http post to a php script. the method works if I
> place it in the onCreate event of the application but gets a
> ConnectionTimeOut error when it tries to execute it from the service.
> Here is an example of my method
>
> String url = "http://myurl/"; +
>                "?tmpl=javascript" +
>                "&mode=recieved" +
>                "&id=" + id;
>                URI uri = null;
>                try {
>                        url = url.replace(" ", "%20");
>                        uri = new URI(url);
>                } catch (URISyntaxException e1) {
>                        // TODO Auto-generated catch block
>                        e1.printStackTrace();
>                }
>                HttpGet httpGet = new HttpGet(uri);
>                HttpParams httpParameters = new BasicHttpParams();
>                // Set the timeout in milliseconds until a connection is
> established.
>                int timeoutConnection = 10000;
>                HttpConnectionParams.setConnectionTimeout(httpParameters,
> timeoutConnection);
>                // Set the default socket timeout (SO_TIMEOUT)
>                // in milliseconds which is the timeout for waiting for
> data.
>                int timeoutSocket = 10000;
>                HttpConnectionParams.setSoTimeout(httpParameters,
> timeoutSocket);
>
>                DefaultHttpClient httpClient = new
> DefaultHttpClient(httpParameters);
>                try {
>                        HttpResponse response = httpClient.execute(httpGet);
>                } catch (ClientProtocolException e) {
>                        System.out.println(e.getLocalizedMessage());
>                        e.printStackTrace();
>                } catch (IOException e) {
>                        System.out.println(e.getLocalizedMessage());
>                        e.printStackTrace();
>                }
>
> I have no idea why the service would get a time out error but the
> application activity would not. I am baffled.
>
> --
> 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]<android-developers%[email protected]>
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en




-- 
Kumar Bibek
http://techdroid.kbeanie.com
http://www.kbeanie.com

-- 
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

Reply via email to