我正在尝试实现简单的登录窗口,但它给文件未找到异常...。
我对此进行了很多搜索,但是它没有运行...
受保护的字符串doInBackground(String ... voids){
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
String type=voids[0];
String url="http://192.168.0.105/rootlogin.php";
if(type.equals("initlogin")){
try {
String un=voids[1];
String up=voids[2];
URL u=new URL(url);
HttpURLConnection huc= (HttpURLConnection) u.openConnection();
huc.setRequestMethod("POST");
huc.setDoOutput(true);
huc.setDoInput(true);
OutputStream os=huc.getOutputStream();
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));
String post_data= URLEncoder.encode("un","UTF-8")+"="+URLEncoder.encode(un,"UTF-8")+"&"+
URLEncoder.encode("up","UTF-8")+"="+URLEncoder.encode(up,"UTF-8");
bw.write(post_data);
bw.flush();
bw.close();
os.close();
InputStream is=huc.getInputStream();
//InputStream error = huc.getErrorStream();
BufferedReader br=new BufferedReader(new InputStreamReader(is,"ISO-8859-1"));
String result="";
String line="";
while ((line=br.readLine())!=null){
result +=line;
}
br.close();
is.close();
huc.disconnect();
return result;
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
return null;
}
最佳答案
可能是您的php文件不在服务器的根目录中。检查文件路径并更正URL。
关于java - 为httpURLConnection获取java.io.FileNotFoundException,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/43259387/