Hi i am trying to to get data from service running on server all things is running fine but all of the sudden it gave error "EOF Exception"

my code is,

   public void fetchJSON(){
       Thread thread = new Thread(new Runnable(){
             @Override
             public void run() {
             try {
                URL url = new URL(urlString);
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setReadTimeout(30000 /* milliseconds */);
                conn.setConnectTimeout(50000 /* milliseconds */);
                conn.setRequestMethod("POST");
                conn.setRequestProperty("User-Agent", "GYUserAgentAndroid");
                conn.setRequestProperty("Content-Type", "application/json");
                conn.setDoInput(true);
                conn.setUseCaches (false);
                if (Build.VERSION.SDK != null && Build.VERSION.SDK_INT > 13)
                {
                    conn.setRequestProperty("Connection", "close"); 
                }
                conn.connect();
                System.out.println("Before url.openStream()");
             InputStream stream = conn.getInputStream();
             System.out.println("After url.openStream()");
          String data = convertStreamToString(stream);
          jb=readAndParseJSONDB(data);
             stream.close();
             }
             catch (EOFException e) { e.printStackTrace();}
             catch (Exception e) {
                e.printStackTrace();
             }
             }
          });
           thread.start(); 
       }

On line InputStream stream = conn.getInputStream(); i do get this error stack trace is given below,

Before url.openStream()
java.io.EOFException
libcore.io.Streams.readAsciiLine(Streams.java:203)
libcore.net.http.HttpEngine.readResponseHeaders(HttpEngine.java:560)
libcore.net.http.HttpEngine.readResponse(HttpEngine.java:813)
libcore.net.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:274)
libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:168)
com.example.test.HandleJSON$1.run(HandleJSON.java:74)
java.lang.Thread.run(Thread.java:856)

Hopes for you suggestion

Thanks

Related posts

Recent Viewed