越来越java.io.FileNotFoundException为HttpURLConnection的

问题描述:

我想实现简单的登录窗口,但它给文件未发现异常.... 找遍了很多关于这个,但它没有运行...越来越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; 
} 
+0

当您在浏览器中打开该网址时会发生什么?你也收到404吗?如果没有:尝试POST到该URL并查看会发生什么。 – f1sh

+0

它显示消息“登录失败” –

赔率是你的PHP文件不位于您的服务器的根目录下。检查文件路径并更正URL。

bw.close(); 
os.close(); 

删除那些两次。到处!它也会关闭插座。

+0

我试过,但我得到相同的错误 –

+0

是的。那些是为了以后。你现在没有联系。 – greenapps