How did you solve this? On Oct 7, 5:25 pm, abhishek akhani <[email protected]> wrote: > Solved... > > On Oct 6, 3:51 pm, abhishek akhani <[email protected]> wrote: > > > > > > > > > HI, > > > i want to use Google's ajax local search API in my android > > application. > > > but i am getting following error: > > > 10-06 15:21:04.386: WARN/System.err(662):java.net.SocketException: > >Permissiondenied > > 10-06 15:21:04.396: WARN/System.err(662): at > > org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocketImpl(Nat > > ive > > Method) > > 10-06 15:21:04.426: WARN/System.err(662): at > > org.apache.harmony.luni.platform.OSNetworkSystem.createStreamSocket(OSNetwo > > rkSystem.java: > > 186) > > 10-06 15:21:04.426: WARN/System.err(662): at > > org.apache.harmony.luni.net.PlainSocketImpl.create(PlainSocketImpl.java: > > 265) > > 10-06 15:21:04.426: WARN/System.err(662): at > > java.net.Socket.checkClosedAndCreate(Socket.java:873) > > 10-06 15:21:04.436: WARN/System.err(662): at > > java.net.Socket.connect(Socket.java:1020) > > 10-06 15:21:04.436: WARN/System.err(662): at > > org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnection.<init>(HttpConnection.java: > > 62) > > 10-06 15:21:04.446: WARN/System.err(662): at > > org.apache.harmony.luni.internal.net.www.protocol.http.HttpConnectionPool.get(HttpConnectionPool.java: > > 88) > > 10-06 15:21:04.446: WARN/System.err(662): at > > org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.getHTTPConnection(HttpURLConn... > > 927) > > 10-06 15:21:04.455: WARN/System.err(662): at > > org.apache.harmony.luni.internal.net.www.protocol.http.HttpURLConnectionImpl.connect(HttpURLConnectionImpl... > > 909) > > > Here is my code for making request: > > > --------------------------------------------------------------------------- > > --------------------------------------------------------------------------- > > ------------------------------------ > > > String url = "http://ajax.googleapis.com/ajax/services/search/local? > > v=1.0&q=pet+store"; > > String result = MakeRequest(url); > > > public static String MakeRequest(String url) throws Exception{ > > String rdata=""; > > try { > > > System.setProperty("http.keepAlive", "false") ; > > > InputStream is = null; > > URL myFileUrl = new URL(url); > > > HttpURLConnection conn= > > (HttpURLConnection)myFileUrl.openConnection(); > > conn.setDoInput(true); > > conn.setDoOutput(true); > > conn.setRequestMethod("GET"); > > conn.connect(); > > is = conn.getInputStream(); > > int code = conn.getResponseCode(); > > > if(code == 200){ > > if(is!=null){ > > ByteArrayOutputStream outputStream = new > > ByteArrayOutputStream(); > > int len=-1; > > byte[] buff=new byte[1024]; > > while((len=is.read(buff))!=-1){ > > outputStream.write(buff,0,len); > > } > > byte[] bs = outputStream.toByteArray(); > > rdata= new String(bs); > > is.close(); > > conn.disconnect(); > > outputStream.flush(); > > outputStream.close(); > > } > > }else if(code == -1){ > > is.close(); > > conn.disconnect(); > > MakeRequest(url); > > } > > else{ > > throw new Exception("Please check Internet > > connection:"+code); > > //return null; > > } > > //is.close(); > > conn.disconnect(); > > } catch (Exception e) { > > throw e; > > //return null; > > } > > > return rdata; > > } > > > public static InputStream OpenHttpConnection(String urlString) > > throws IOException { > > InputStream in = null; > > int response = -1; > > > URL url = new URL(urlString); > > URLConnection conn = url.openConnection(); > > > if (!(conn instanceof HttpURLConnection)) > > throw new IOException("Not an HTTP connection"); > > > try { > > HttpURLConnection httpConn = (HttpURLConnection) > > conn; > > httpConn.setAllowUserInteraction(false); > > httpConn.setInstanceFollowRedirects(true); > > httpConn.setRequestMethod("POST"); > > httpConn.connect(); > > > response = httpConn.getResponseCode(); > > if (response == HttpURLConnection.HTTP_OK) { > > in = httpConn.getInputStream(); > > } > > } catch (MalformedURLException e1) { > > e1.printStackTrace(); > > } catch (Exception ex) { > > throw new IOException("Error connecting"); > > } > > return in; > > } > > > --------------------------------------------------------------------------- > > --------------------------------------------------------------------- > > > Please suggest what to do...............
-- 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

