1

我一直在尝试从我的 Android 应用程序调用服务器,但我不断收到 500 错误

java.io.FileNotFoundException: https:// 有效 URL

但是当我使用相同的代码块并作为 Java 应用程序运行时,它返回 200 响应并且工作正常。

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()));

以上是我在两个应用程序中使用的代码。使用 HTTPClient 可能会解决问题,但我还没有尝试过。但由于我一直在使用 HTTPURLConnection,我想知道是否有可能的解决方案。

这是痕迹

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)

顺便说一句,我将其作为后台线程运行。这解释了 AsyncTask 部分。我不确定这是否与这里有关。

有类似的线程

4

0 回答 0