W/System.err: java.io.FileNotFoundException:http://192.168.0.102/login/register.php
I'm trying to send info in a database, through my android device but.. it showing this error...
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();
Exception:
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)
You may receive a FileNotFoundException if you get a bad response from the server (response code != HttpURLConnection.HTTP_OK).
int responseCode = httpURLConnection.getResponseCode();
if (responseCode != HttpURLConnection.HTTP_OK) {
inputStream = httpURLConnection.getErrorStream();
} else {
inputStream = httpURLConnection.getInputStream();
}
You can try accessing http://192.168.0.102/login/register.php in your dekstop web browser to prove that indeed it is available or this is the correct url. You can just comment out the rest of the code in your register.php file and then echo something like
<?php echo 'hello'; ?>
and see if it gets displayed on your browser. It might be that the url for register.php might be wrong.
EDIT
As requested by Ankit, I will provide a short guide of how to make Wamp online. It can help solve the 'Forbidden' issue and I have also posted a Youtube link to help you further. My advice is that do not set a very defined IP like 192.168.{other values}, inside your httpd.conf file as some blogs do. My guide allows any ip address, which makes it possible to allow connections without having to keep changing the .conf files.
OPTION 1: USING THE PUT ONLINE OPTION
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.
OPTION 2: CHANGING 'HTTPD.CONF' AND 'HTTPD-VHOST.CONF' FILES
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.
I know that this is not xml code, but this format just makes it more appealing to read through. Other helpful links that can help you are this, this, this(has helpful images) and How to allow wamp server 3.0 access on another computer | how to solve "Forbidden" access of wamp - Youtube link:
Related
I have a Xamarin app and localhost API. I'm trying to connect to the API from the app, but it could not be found. I edited my applicationhost.config file and I tried localhost, 10.0.2.2 and my IP address in the call, but it was not working.
So, how do I configure simple API access? (The API itself is working well)
There is simple workaround to connect Emulator & Simulator to localhost API.
Download third party software NgRok for Windows at any specific location of your PC. It just contains one executable file called ngrok.exe (you not need to install it).
Now execute your service on your preferred browser. Than follow below steps.
Open your ngrok.exe file path in command prompt
Keep your service url (take from your browser) with prefix ngrok http --host-header=rewrite and hit enter.
Now go to your browser where you have executed your service open new tab and type localhost:4040 than press enter -->Go to status there you will find your public url which you can use in your mobile application.
Note: Url structure should be like this public const string BaseUri = "https://8c56892f.ngrok.io/"; followed by / in last. Try not to append unnecessary /.
Benifits
You can debug services from one Visual Studio to another.
Your url will be active until you close command prompt.
In browser or command prompt track your requests status like Ok, Not found etc.
For more information visit this https://www.c-sharpcorner.com/article/exposing-local-web-server-to-internet-using-ngrok/
Hope it help you.
That 10.0.2.2 address is used for the Google emulators. For the Microsoft emulator you want to use 169.254.80.80. If that doesn't work then it must mean you have the firewall on and it's blocking the traffic. That can be solved by adding a new incoming rule for the program or port.
I have created simple listview apps using xamarin form and data are coming from webservices.
My current problem is , i couldnt connect internet my android emulator. Please anyone can guide how to do?
My Error image
Notes: My PC connected internet via LAN.
Connecting to the Internet from an Android emulator can be tricky.
One common issue is falling foul of a network proxy. If you have one on your network you need to configure it on the emulator.
Here is an article detailing Android emulator network settings.
You should check the connection settings of your emulator when you create one try creating one more emulator and revert us so we can help you create one.
The way i suggest you do it is use the emulators that visual studio provides check visual emulators in your respected search menu to find it .
One of the problems could be you do not have internet permissions which you can update in your manifest using this line:
<uses-permission android:name="android.permission.INTERNET" />
If this doesn't work follow the steps below :
1.Go to settings->Wireless & networks->mobile networks->Access Point Names.
2.Press menu button. an option menu will appear.
3.from the option menu select New APN.
4.Click on Name. provide name to apn say My APN.
5.Click on APN. Enter www.
6.Click on Proxy. enter your proxy server IP. you can get it from internet explorers internet options menu.
7.click on Port. enter port number in my case it was 8080. you can get it from internet explorers internet options menu.
8.Click on User-name. provide user-name in format domain\user-name. generally it is your systems login.
9.Click on password. provide your systems password.
10.press menu button again. an option menu will appear.
11.press save. try n run your browser. hope its work for you it worked for me. good luck.
I have this in my .htaccess to require a password but allow certain whitelisted IP addresses without authentication.
Order deny,allow
Deny from all
AuthType basic
AuthName "Admins Only"
AuthUserFile /etc/apache/.htpasswd
Require valid-user
#replace xxx with IP allowed
Allow from xxx.xxx.xxx.xxx
Satisfy any
Using Apache 2.2.16 on RedHat.
Two things are happening here:
It still asks the whitelisted addresses for password, and
when I visit the site on my Android device, I can see the website behind the auth popup, then when I cancel it, I can still browse the site.
Has anyone else experienced similar symptoms and have suggestions?
Note: When I remove the Deny, Allow, and Satisfy rules, the auth works as expected.
Turns out the Satisfy any directive was being met in a couple other locations. Particularly in my apache httpd.conf file, and an .htaccess in a subfolder of the DocumentRoot.
If you're having similar issues with satisfy any, check any other possible locations where .htaccess may be called from and comment out any Order deny,allow and Allow from all statements. Using something along the lines of these commands helped me find the problems (in linux via ssh):
cd /www/documentroot && find -name .htaccess
Or
grep -rli 'allow from all' .
(the 2nd command will search through files so it will take more time)
Or find it in your apache configuration files. Note that you shouldn't have to change the apache config if AllowOverride all is set for your vhost.
I build a worklight application. create android app and test this application with local machine , its working fine with emulator.but when i try to test this application with android tablet it through error "The Application failed connecting to the service".
I try to find application-descriptor.xml and fix localhost to 192.168.1.1:8080
my ip local machine,but it not working.In my tablet I can't to go to 192.168.1.1:8080/console/index.html
Can anybody help me regarding this issue. how can i fix this one in my worklight android application and run it on my android tablet
Some things to check:
- Are your tablet and your worklight development machine on the same wireless network? (they need to be!)
- Does your computer have a firewall on it which may need configuring to let the traffic through. As a test you could briefly disable the firewall and see if you then have access (subject to disclaimer of the risk involved in disabling the firewall). A test without disabling the firewall would be to try accessing 192.168.1.1:8080 from another desktop/laptop machine on that same subnet.
Check ip in local machine ipconfig ( field Adaptador de Ethernet )
Set this IP in field host name configuration server.
Rebuild
The other test is to check the direction in other machine, in the same network.
In a command window, run ipconfig and copy the IPv4 address. This is the IP address you need to place as the value for worklightServerRootURL in the file application-descriptor.xml.
The IP address you are usingnow does not look to me like the correct (public) IP address that you need to use. Try my above suggestion.
How about adding "192.168.181.1:8080" in application-descriptor.xml?
I would suggest the following debugging steps:
a) Go to your device browser and browse to http:
//xx.xx.xx.xx:8080/console
-> If this doesn't work, you have an obvious ip address issue. Then you have to figure out why, maybe you have a Symantec thingy that blocks any incoming traffic to your desktop - which they do. You should do an explicit allow.
b) If a) works, then you need to check in your code to make sure your app does try to connect to the server at startup. Or else the app will only try to connect when it calls adapter.
Now, go to your code. open the initOptions.js file. I typically, would set connectOnStartup to true, but also enable the onConnectionFailure so that it runs offline when there is no connection.
var wlInitOptions = {
// # Should application automatically attempt to connect to Worklight Server on application start up
// # The default value is true, we are overriding it to false here.
connectOnStartup : true,
// # The callback function to invoke in case application fails to connect to Worklight Server
onConnectionFailure: function (){wlCommonInit();},
// # Worklight server connection timeout
timeout: 2000,
};
3) Make sure you have the right URL in the application-descriptor.xml
<worklightServerRootURL>http://xx.xx.xx.xx:8080
</worklightServerRootURL>
If you are using the consumer edition (the real purchased WL), your URL would be.
<worklightServerRootURL>http://xx.xx.xx.xx:9080/worklight
</worklightServerRootURL>
(Note no space in between those URL - it's just this website putting a space there when there is a line break)
Redeploy your code to the WL server and create a new APK file. Update your device with the new APK file.
4) Do a test with the console again, you should see the console. Click on the Preview app link, it should work.
5) Now that you have updated your code on the server and the APK file. Open it up again on the device.
Do you still see the error message?
If things still not work.
6) Go to the app setting, since you have enable offline mode, it would allow you to access the App settings (it's the 4th button in Android) Go to Worklight Settings. Select Server Address -> Add the worklight URL to the Server URL. When you go back to the app, this will automatically reload the content from your WL server.
I know that I have to edit the /system/etc/hosts to map an IP address to a host name, but it seems that I can't edit the file. Is it because my android phone is not rooted?
Kindly advise. Thanks.
You can use the following guide and application to setup rules for specific domains.
Download (Daedalus) and open the application.
Click on the menu then click “Servers”
Click the add button and add the two google servers “8.8.8.8” and “8.8.4.4”, You can substitute these for your preferred DNS provider as well.
Activate these dns servers in the menu by clicking on “Settings”
Then select Google and Google 2 from the settings. Also activate Advance settings and select the two following options in the image below
Back to the menu now, Click on “Rules”.
Add a new rule for each development mode, Live, staging, dev. Filename is not crucial, just make something up.
Hit sync rule before leaving to make sure the file is downloaded.
Tap and activate the mode you wish to be in, You can activate more than one at a time so be careful as this will override one or the other.
In the menu go to home, and hit the “Activate” button.
Source: https://silocitylabs.com/post/2018/03/02/changing-dns-settings-for-android-development/
Try to remount using adb and edit the file
Why do you need to edit the hosts file?
You can simply add your host to a local DNS (e.g. the DNS announced by a local DHCP-Server in your Wifi-Network) or even in the real global DNS.