首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >W/System.err: java.io.FileNotFoundException

W/System.err: java.io.FileNotFoundException
EN

Stack Overflow用户
提问于 2019-06-06 20:13:22
回答 2查看 1.9K关注 0票数 0
代码语言:javascript
复制
W/System.err: java.io.FileNotFoundException:http://192.168.0.102/login/register.php

我正试着通过我的android设备发送数据库中的信息,但是..它显示了这个错误...

代码语言:javascript
复制
        try {
            URL url = new URL(reg_url);

            HttpURLConnection httpURLConnection = (HttpURLConnection)url.openConnection();

            httpURLConnection.setRequestMethod("POST");

            httpURLConnection.setDoOutput(true);
            httpURLConnection.setConnectTimeout(10000);
            httpURLConnection.setReadTimeout(100000);

            OutputStream os = httpURLConnection.getOutputStream();

            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(os,"UTF-8"));


            String data = URLEncoder.encode("userid","UTF-8") +"="+ URLEncoder.encode(userid,"UTF-8")+"&"+
                    URLEncoder.encode("email","UTF-8") +"="+ URLEncoder.encode(user_email,"UTF-8")+"&"+
                    URLEncoder.encode("password","UTF-8") +"="+ URLEncoder.encode(user_pass,"UTF-8");

            bufferedWriter.write(data);

            bufferedWriter.flush();
            bufferedWriter.close();
            os.close();

例外:

代码语言:javascript
复制
W/System.err: java.io.FileNotFoundException:
http://192.168.0.102/login/register.php
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:250)
at com.loginapp.logintest.background$override.doInBackground(background.java:80)
at com.loginapp.logintest.background$override.access$dispatch(background.java)
at com.loginapp.logintest.background.doInBackground(background.java)
at com.loginapp.logintest.background.doInBackground(background.java:22)
EN

回答 2

Stack Overflow用户

发布于 2019-06-06 20:30:38

如果收到来自服务器的错误响应(响应码!= HttpURLConnection.HTTP_OK),您可能会收到FileNotFoundException

代码语言:javascript
复制
int responseCode = httpURLConnection.getResponseCode();

if (responseCode != HttpURLConnection.HTTP_OK) {
    inputStream = httpURLConnection.getErrorStream();
} else {
    inputStream = httpURLConnection.getInputStream();
}
票数 1
EN

Stack Overflow用户

发布于 2019-06-06 20:33:35

您可以尝试在您的dekstop web浏览器中访问http://192.168.0.102/login/register.php,以证明它确实可用,或者这是正确的url。您只需注释掉register.php文件中的其余代码,然后回显如下所示

代码语言:javascript
复制
<?php echo 'hello'; ?> 

看看它是否会显示在你的浏览器上。可能是register.php的url错误。

编辑

应Ankit的要求,我将提供如何使Wamp在线的简短指南。它可以帮助解决“禁忌”的问题,我还在Youtube上发布了一个链接来进一步帮助你。我的建议是,不要像一些博客那样在httpd.conf文件中设置一个非常明确的IP,比如192.168.{other values}。我的指南允许任何ip地址,这使得允许连接而不必不断更改.conf文件成为可能。

联机选项1:使用PUT 选项

代码语言:javascript
复制
1.  Using the Put Online Option
    There is a new option on the icon tray of wamp server if you left click on it, at the bottom you will see 'Put online'. You can enable it. 
    Though I use it, I am not sure if it makes Wamp online without prior changes to *httpd.conf* and *httpd-vhost.conf* since I had 
    already made these changes before I started using it. 
    What I know is that after changing those files, my Wamp is accessible online even without clicking 'put online' option.

2.  Go to '*Control Panel > System and Security > Windows Defender Firewall > Allow an App or feature through Windows Defender firewall*' 
    Click Allow another app and under Path, browse to the location of httpd.exe (in my case it is '*C:\wamp64\bin\apache\apache2.4.23\bin\http.exe*').
    Then select the checkboxes for 'private' and 'public' and then click ok.
3.  Restart your Wampserver and click Put online.
4.  Please note that if you have skype, then you may need to do this if you icon does not change to green:
    i.      open skype 
    ii.     then under  Tools > Connections, untick the option for "use port 80 and 443 for additional incoming connection". 
    iii.    Save and then close skype
    iv.     Restart Wampserver.
5.  Open you Windows hotspot and share it with your android phone, or vice versa.
6.  Open cmd.exe and run the command '*ipconfig*'. Get your IP address 
    e.g. 192.168.{other values}, mine is usually 192.168.137.1 but it is currently showing 192.168.43.66.
7.  In your android phone, type '*http://<that ip address from cmd>*' on your Web browser. It should load the Wampserver page on the browser. 

选项2:更改'HTTPD.CONF‘和'HTTPD-VHOST.CONF’文件

代码语言:javascript
复制
Please note that there is no deletion that is done. 
For all the lines that I have placed here, you simply need to change from some old value to a new value 
e.g require local to require granted, etc, or add a line if it is missing. 

1. Open httpd.conf file (found under '*c:\wamp64\bin\apache\apache{apache_version}\conf\httpd.conf*')
2. Save a copy of this original file somewhere else just in case of anything.
3. Locate the following lines and change them to be as below;

        ..........
        #Listen 12.34.56.78:80
        Listen 0.0.0.0:80
        Listen [::0]:80

        ..........  

        # If your host doesn't have a registered DNS name, enter its IP address here.
        ServerName localhost:80

        ..........

        # Deny access to the entirety of your server's filesystem. You must
        # explicitly permit access to web content directories in other 
        # <Directory> blocks below.
        #
        <Directory />
            AllowOverride none
            Require all granted
        </Directory>

        ..........

        DocumentRoot "${INSTALL_DIR}/www"
        <Directory "${INSTALL_DIR}/www/">
            .......
            AllowOverride all
            .......
            Require all granted
        </Directory>

        .........
        <Files ".ht*">
             Require all granted
        </Files>

        .........
        <Directory "${INSTALL_DIR}/cgi-bin">
            AllowOverride None
            Options None
            Require all granted
        </Directory>

4.  Open httpd-vhost.conf file (found under '*c:\wamp64\bin\apache\apache{apache_version}\conf\extra\httpd-vhost.conf*')
5.  Save a copy of this original file somewhere else just in case of anything.
6.  Change the code to:
    (please note that if you have other extra lines inside that are not here, please DO NOT delete them. 
     Just add what is missing and change what appears needs to be changed e.g. Require local to require all granted)

    # Virtual Hosts
    #

    <VirtualHost *:80>
        ServerName localhost
        DocumentRoot c:/wamp64/www
        <Directory  "c:/wamp64/www/">
            Options +Indexes +Includes +FollowSymLinks +MultiViews
            AllowOverride All
            Require all granted
        </Directory>
    </VirtualHost>
    #

7.  Open hosts file (path is '*C:\Windows\System32\drivers\etc\hosts*') and change or add these lines to be these 
    (you have to launch notepad or any other text editor like notepad++ as administrator so that you can be allowed to change them):
    # localhost name resolution is handled within DNS itself.
    #   127.0.0.1       localhost
    #   ::1             localhost

8.  Go to '*Control Panel > System and Security > Windows Defender Firewall > Allow an App or feature through Windows Defender firewall*' 
    Click Allow another app and under Path, browse to the location of httpd.exe (in my case it is '*C:\wamp64\bin\apache\apache2.4.23\bin\http.exe*').
    Then select the checkboxes for 'private' and 'public' and then click ok.
9.  Restart your Wampserver and everything should be okay.
10. Please note that if you have skype, then you will need to:
    i.      open skype 
    ii.     then under  Tools > Connections, untick the option for "use port 80 and 443 for additional incoming connection". 
    iii.    Save and then close skype
    iv.     Restart Wampserver.

11. Open you Windows hotspot and share it with your android phone, or vice versa.
12. Open cmd.exe and run the command '*ipconfig*'. Get your IP address 
    e.g. 192.168.{other values}, mine is usually 192.168.137.1 but it is currently showing 192.168.43.66.
13. In your android phone, type 'http://<that ip address from cmd>' on your Web browser. It should load the Wampserver page on the browser. 

我知道这不是xml代码,但这种格式只是让它更容易阅读。其他有帮助的链接有thisthisthis(has helpful images)How to allow wamp server 3.0 access on another computer | how to solve "Forbidden" access of wamp - Youtube link

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56477382

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档