I've been trying to call the server from my Android App but I keep getting 500 ERROR
java.io.FileNotFoundException: https:// VALID URL
But when i use the same code block and run as Java application, it returns 200 response and works fine.
URL url = new URL("https://VALID URL");
HttpURLConnection conn = null;
conn = (HttpURLConnection)url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/json");
conn.setRequestProperty("http.protocol.version", "HTTP/1.1");
conn.setRequestProperty("http.socket.timeout", "30");
conn.setRequestProperty("http.protocol.content-charset", "UTF-8");
conn.setRequestProperty("apiKey","90c67a05-7613-48c5-a986-4d4ba5649cb7");
conn.setRequestProperty("authId",authID);
conn.setRequestProperty("connectionTicket",connTicket);
conn.setRequestProperty("State", "Open,Pending,Canceled,Rejected,Completed");
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
int httpresponse = conn.getResponseCode();
System.out.println(httpresponse);
System.out.println(conn.getErrorStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(conn.getInputStream()));
The above is the code I used in both of my applications. Using HTTPClient might solve the problem but I haven't tried yet. But since I've been using HTTPURLConnection throughout, I would like to know if there is a possible solution to this.
This is the trace
06-29 11:35:00.438: W/System.err(5000): java.io.FileNotFoundException: https://VALID URL (edited)
06-29 11:35:00.438: W/System.err(5000): at libcore.net.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:177)
06-29 11:35:00.478: W/System.err(5000): at libcore.net.http.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:270)
06-29 11:35:00.488: W/System.err(5000): at com.Tabs.List$Populate_List.doInBackground(List.java:126)
06-29 11:35:00.488: W/System.err(5000): at com.Tabs.List$Populate_List.doInBackground(List.java:1)
06-29 11:35:00.548: W/System.err(5000): at android.os.AsyncTask$2.call(AsyncTask.java:264)
06-29 11:35:00.598: W/System.err(5000): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:305)
06-29 11:35:00.648: W/System.err(5000): at java.util.concurrent.FutureTask.run(FutureTask.java:137)
06-29 11:35:00.648: W/System.err(5000): at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:208)
06-29 11:35:00.678: W/System.err(5000): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1076)
06-29 11:35:00.698: W/System.err(5000): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:569)
06-29 11:35:00.708: W/System.err(5000): at java.lang.Thread.run(Thread.java:856)
I am btw running this as a background thread. That explains the AsyncTask part. I am not sure if that has got something to do here.
there are similar threads