我是Java和Android Studio的初学者。我已经编写了Android Studio和Wamp作为服务器和Genymotion作为模拟器的代码。所有代码都工作正常,我可以通过使用我的.php文件与mysql进行交互
然后我决定将代码传输到真实服务器。
但我收到此错误: java.io.FileNotFoundException:http://burj.1shahrvand.com/Burj/BikerLogin.php
该文件可用check it here,但我收到异常未找到文件
代码是这样的:
String uri = rp.getUri();
if(rp.getMethod().equals("GET")){
uri += "?" + rp.getEncodedParams();
}
HttpURLConnection connection;
try {
URL url = new URL(uri);
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod(rp.getMethod());
if (rp.getMethod().equals("POST")){
connection.setDoOutput(true);
connection.setDoInput(true);
OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
writer.write(rp.getEncodedParams());
writer.flush();
}
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line);
}
return sb.toString();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
Log.i("HESAM Original", e.getMessage());
e.printStackTrace();
}
return null;
感谢您的帮助!
答案 0 :(得分:1)
如果您在服务器响应404或410状态代码后致电FileNotFoundException
,您将获得getInputStream
。
如果要避免异常,请检查响应状态代码是否为2xx代码。如果不是,请使用getErrorStream
代替getInputStream
。
答案 1 :(得分:0)
就我而言,我的Cpanel中有一个选项。这是MOD安全,只需关闭它,15分钟后我的应用程序正常工作。
答案 2 :(得分:0)
只需要在URL字符串中添加端口名称(:8080)和localhost ip地址,就像我一样:
String login_url =“http://192.168.0.136:8080/login.php”;