============問題描述============
在AVD上測試沒問題。換到設備上時報FileNotFound的異常,經常報這個異常。各位幫忙看看。
代碼如下:
public class HttpAssist {
public static String doPost(JSONObject json) throws IOException{
URL postUrl = new URL(Config.url);
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.connect();
OutputStreamWriter out = new OutputStreamWriter (connection
.getOutputStream());
out.write( Config.getParameterName + "=" + json.toString());
out.flush();
out.close(); // flush and close
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream(),"utf-8"));
String line="";
String res = "";
while ((line = reader.readLine()) != null){
res += line;
System.out.println(line);
}
reader.close();
connection.disconnect();
return res;
}
}
異常如下:
也不是每次都報,但是經常會報這個異常。查了半天也沒查到點有用的東西。各位,就看你們了。。。
============解決方案1============
獲取流之前 建議 判斷responseCode是200.
============解決方案2============
那你就把返回的狀態碼判斷下看看
