我想實現簡單的登錄窗口,但它給文件未發現異常.... 找遍了很多關於這個,但它沒有運行...越來越java.io.FileNotFoundException爲HttpURLConnection的
保護字符串doInBackground(字符串...空隙){
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;
}
當您在瀏覽器中打開該網址時會發生什麼?你也收到404嗎?如果沒有:嘗試POST到該URL並查看會發生什麼。 – f1sh
它顯示消息「登錄失敗」 –