Lack of access to localhost laravel project API route in android studio - android

I have a laravel project contains an RestFull API. I want to access to this API from android studio. I use retrofit library.When I run server through artisan, can't access localhost laravel app routes to android studio.According to this question accessing-localhost-laravel-app-routes-to-android-studio-failed, I change base url to http://192.168.1.103:8000/halamooz/public/api/ and run the laravel app with apache server.For this work, I follow this guideline Laravel practical guide for using XAMPP.Of course I don't use XAMPP and install apache server individually. I access web route from browser but when I try to access API route from postman or android studio I receive 404 page not founded error.What is my mistake?
I put this lines in httpd-vhosts file:
<VirtualHost *:80>
DocumentRoot "C:/apache/htdocs/halamooz/public"
ServerName exampledomain.com
ServerAlias exampledomain.com
<Directory "C:/apache/htdocs/halamooz/public">
AllowOverride All
Require all Granted
</Directory>
</VirtualHost>

In httpd.conf file find
Listen 80
and below that write
Listen 8060
Then goto httpd-vhosts.conf
<VirtualHost *:8060>
ServerAdmin webmaster#dummy-host2.example.com
DocumentRoot "C:/apache/htdocs/halamooz/public"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error.log"
CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>
Replace DocumentRoot with your path of project. Hope this help you

I finally did these steps and My problem solved.
Step 1:
Put your laravel project into C:\apache\htdocs.
Step 2: Run as administrator notepad app and open hosts file from C:\Windows\System32\drivers\etc path and add this line to end of file.
127.0.0.1 exampledomain.com www.exampledomain.com
Step 3: Open httpd-vhosts file from C:\apache\conf\extra path and add these lines to end of file:
<VirtualHost *:80>
DocumentRoot "C:/apache/htdocs/NameOfProject/public"
ServerName exampledomain.com
ServerAlias exampledomain.com
<Directory "C:/apache/htdocs/NameOfProject/public">
AllowOverride All
Require all Granted
Step 4:Uncomment this line from C:\apache\conf\httpd.conf file.
Include conf/extra/httpd-vhosts.conf
Step 5:Use this Url to access API in postman or android studio project.
http://{IPv4 of your computer}:8000/{ProjectName}/public/api/{desired method}
For example:
http://192.168.1.3:8000/halamooz/public/api/login
Notice: Your Android device and computer must be on a same network Internet.

Related

Access to Laravel app from Android phone in local network

I have a problem. I build an app with Laravel on my computer (IP: 192.168.1.121), I try to access to my app with my Android phone in local network. When I try to reach 192.168.1.121/myapp/public I have a 404 not found but in my computer all work.
On another computer, I can modify host file to add
192.168.1.121 edcintra.test
And that works perfectly.
define ROOT "C:/laragon/www/EDCIntra/public/"
define SITE "EDCIntra.test"
<VirtualHost *:80>
DocumentRoot "${ROOT}"
ServerName ${SITE}
ServerAlias *.${SITE}
<Directory "${ROOT}">
Options Indexes FollowSymLinks
AllowOverride All
allow from all
Require all granted
</Directory>
</VirtualHost>
<VirtualHost *:443>
DocumentRoot "${ROOT}"
ServerName ${SITE}
ServerAlias *.${SITE}
<Directory "${ROOT}">
AllowOverride All
Require all granted
</Directory>
SSLEngine on
SSLCertificateFile C:/laragon/etc/ssl/laragon.crt
SSLCertificateKeyFile C:/laragon/etc/ssl/laragon.key
</VirtualHost>
This is my conf in Apache... Someone already have this problem?

How to include Internet Permission in Kivy? (Android 6)

I want to use the standard Python module urllib2 in my Kivy App which requires access to the Internet. But when I uncomment #android.permissions = INTERNET
and package the App the App doesn't inform me about the Internet Permission while installing the .apk and when I'm using urllib2 my App crashes (probably because no Internet Permission)
Thx in advance!
In this case the modification is not made in the python code but in the buildozer.spec file.
Inside this file on line 87 you will find "# (list) Permissions" on the line below it will have "# android.permissions = INTERNET" uncomment this line so that the app has internet access permission, if you don't find the line you can copy and paste "android.permissions = INTERNET", this way the apk will be able to connect to the internet, but it may end up with a certificate error "SSL: CERTIFICATE_VERIFY_FAILED error", in this case do the following:
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
that way the error will be resolved.

Positive SSL trusted in Chrome for desktop but not for Android

I have just bought a Positive SSL Certificate but it does not work in Chrome for Android, I get NET::ERR_CERT_AUTHORITY_INVALID. However, everything is OK with the Chrome for desktop.
This is how I configure my apache2 server:
# File /etc/apache2/sites-available/000-default.conf
<VirtualHost *:80>
ServerName example.com
Redirect permanent / https://example.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
ServerName example.com
SSLEngine on
SSLCertificateFile /root/ssl/certificate/example.com.crt
SSLCertificateKeyFile /root/ssl/example.com.key
SSLCertificateChainFile /root/ssl/certificate/intermediates.crt
# In version 2.4.8 or newer
#SSLCACertificateFile /root/ssl/certificate/intermediates.crt
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
And here it's how I created intermediates.crt:
cat COMODORSADomainValidationSecureServerCA.crt COMODORSAAddTrustCA.crt > intermediates.crt
What am I missing?
I thought the intermediates were wrong, but taking a closer look at the Comodo website, your configuration appears to be correct -- the right certificates in the right order.
Have you tried running your site through the SSL Labs Server Test?
After trying almost every combination, I found the solution. I had to create the bundle using all the files: my certificate, the two intermediates and the root.
cat example.com.crt \
COMODORSADomainValidationSecureServerCA.crt \
COMODORSAAddTrustCA.crt \
AddTrustExternalCARoot.crt > intermediates.crt

Webview Localhost Connection refused using 10.0.2.2 address

I'm just making a basic Webview app on an android emulator and cannot connect to a website hosted on my computer.
Here is my code:
Android Manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.emswebviewer"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="14"
android:targetSdkVersion="19" />
<uses-permission android:name="android.permission.INTERNET"/>
Main Activity Java file:
public class MainActivity extends Activity {
private WebView webView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if (android.os.Build.VERSION.SDK_INT > 9) {
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
System.out.println("*** My thread is now configured to allow connection");
}
setContentView(R.layout.activity_main);
webView = (WebView) findViewById(R.id.webView);
webView.loadUrl("http://10.0.2.2:8080");
}
Terminal (Starting website on local host port 8080):
Michaels-MacBook-Pro-5:web michael$ php -S localhost:8080
PHP 5.5.14 Development Server started at Mon Dec 22 14:08:01 2014
Listening on http://localhost:8080
httpd.conf File (Under Apache Folder):
#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/Applications/MAMP/htdocs">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.2/mod/core.html#options
# for more information.
#
Options All
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride All
#
# Controls who can get stuff from this server.
#
Order allow,deny
Allow from all
I am using Mamp and AVD as the emulator.
When I run my app, it returns net::ERR_CONNECTION_REFUSED on the Main activity page.
Do I need to allow external connections somewhere? OR is there something inherently wrong with what I am trying to do?
localhost on your emulator it's not localhost on your desktop. On your desktop you need to run php server with php -S 10.0.2.2:8080 (if that it's your IP). And than access that IP from the emulator with WebView at your app. You can't access desktop's localhost from the emulator (no directly at least). Don't start your server on localhost only.
Look for this file ports.conf and add Listen 8080 if necessary and restart the server.
Using 10.0.2.2 is correct and not wrong in anyway as such. You can see why in the below answer
why do we use 10.0.2.2 to connect to local web server instead of using computer ip address in android client
The issue may be related to your application listening to 127.0.0.1 only and not all interfaces. You need to make sure you use something like below
php -S 0.0.0.0:8080
I saw your bounty question as well, which also answers that you need run your Django server as below
python manage.py runserver 0.0.0.0:8000
PS: And next time your post a bounty #kingraphaII, be kind enough to respond to people and don't just be a ghost
What worked for me was to replace localhost address with my pc laptop, 192.168.2.7, in my case. #gorlok comment helped me towards my solution.
Android Emulator is a separate device. Emulator isn't part You Computer. Emulator cann't access your Local Server.
So Emulator return net::ERR_CONNECTION_REFUSED error.
I found a Simpal way to solve the issue.
Get my local IP address as like 192.168.99.112
To get your IP address open your Tarminal/cmd type ipconfig
Ensure your internet permission in AndroidManifest File
<uses-permission android:name="android.permission.INTERNET"/>
Then
WebView browser = (WebView)findViewById(R.id.webview);
webView.loadUrl("http://192.168.99.112/projectName");

openssl s_client -connect defaulting to subdomain?

I have spent the last two days trying to figure out why my android application was getting a "no peer certificate" exception error when connecting to my website with the following code:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("https://mysite.co.uk/android/login.php");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
I have used the SSL Labs checker and my certificates pass with a grade A and no issues with the SSL chain (I have read many posts on here claiming this to be the problem). Anyway, thinking that it was something wrong with android I was trying many different suggestions.
I spotted a suggestion to enter the following command into my server:
openssl s_client -connect mysite.co.uk:443
When looking at the results, it was printing out the self-signed certificates of my design site! Obviously this is not what is expected!
Here are the three virtual host config files for my main site (domain and www) and then the design site
mysite.co.uk.conf:
# domain: mysite.co.uk
# public: /home/user/public/mysite.co.uk/public
<VirtualHost *:80>
ServerName mysite.co.uk
ServerAlias *.mysite.co.uk
RedirectMatch permanent /(.*) https://mysite.co.uk/$1
</VirtualHost>
<VirtualHost *:443>
Header always set Strict-Transport-Security "max-age=63072000;"
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/mysite.co.uk/mysite.co.uk.crt
SSLCACertificateFile /etc/apache2/ssl/mysite.co.uk/gs_intermediate_ca.crt
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/home/user/public/mysite.co.uk/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin admin#mysite.co.uk
ServerName mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mysite.co.uk/public
# Log file locations
LogLevel warn
ErrorLog /home/user/public/mysite.co.uk/log/error.log
CustomLog /home/user/public/mysite.co.uk/log/access.log combined
</VirtualHost>
www.mysite.co.uk.conf:
# domain: www.mysite.co.uk
# public: /home/user/public/mysite.co.uk/public
<VirtualHost *:80>
ServerName www.mysite.co.uk
ServerAlias *.www.mysite.co.uk
RedirectMatch permanent /(.*) https://www.mysite.co.uk/$1
</VirtualHost>
<VirtualHost *:443>
Header always set Strict-Transport-Security "max-age=63072000;"
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/mysite.co.uk/www.mysite.co.uk.crt
SSLCACertificateFile /etc/apache2/ssl/mysite.co.uk/gs_intermediate_ca.crt
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/home/user/public/mysite.co.uk/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin admin#mysite.co.uk
ServerName www.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mysite.co.uk/public
# Log file locations
LogLevel warn
ErrorLog /home/user/public/mysite.co.uk/log/error.log
CustomLog /home/user/public/mysite.co.uk/log/access.log combined
</VirtualHost>
design.mysite.co.uk.conf:
# domain: design.mysite.co.uk
# public: /home/user/public/mysite.co.uk/design/public
<VirtualHost *:80>
ServerName design.mysite.co.uk
ServerAlias *.design.mysite.co.uk
RedirectMatch permanent /(.*) https://design.mysite.co.uk/$1
</VirtualHost>
<VirtualHost *:443>
SSLEngine On
SSLCertificateFile /etc/apache2/ssl/design.mysite.co.uk/apache.crt
SSLCertificateKeyFile /etc/apache2/ssl/design.mysite.co.uk/apache.key
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory "/home/user/public/mysite.co.uk/design/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin contact#mysite.co.uk
ServerName design.mysite.co.uk
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /home/user/public/mysite.co.uk/design/public
# Log file locations
LogLevel warn
ErrorLog /home/user/public/mysite.co.uk/log/error.log
CustomLog /home/user/public/mysite.co.uk/log/access.log combined
</VirtualHost>
This also sits in my apache config file
SSLUseStapling on
SSLStaplingResponderTimeout 5
SSLStaplingReturnResponderErrors off
SSLCACertificateFile /etc/apache2/ssl/mysite.co.uk/gs_intermediate_ca.crt
SSLStaplingCache shmcb:/var/run/ocsp(128000)
SSLProtocol -ALL +TLSv1 +TLSv1.1 +TLSv1.2
SSLHonorCipherOrder on
SSLCipherSuite ECDHE-RSA-AES128-SHA256:AES128-GCM-SHA256:RC4:HIGH:!MD5:!aNULL:!EDH
SSLInsecureRenegotiation off
When I run:
sudo a2dissite design.mysite.co.uk
sudo service apache2 restart
and then run:
openssl s_client -connect mysite.co.uk:443
Then I get the certificate details of mysite.co.uk and my android app works again. Am I missing something here? Why is my server defaulting to the design site?
because you have multiple hostnames behind the same IP address and each has its own certificate you need to use SNI (server name indication). This sends the required hostname within the SSL handshake. To test this with openssl you have to use the -servername argument, e.g.
openssl s_client -servername mysite.co.uk -connect mysite.co.uk:443
While all current browser use SNI by default, it looks like that android does not use SNI by default and thus will probably get only the certificate from the default server. I'm not an android programmer myself, but there are several discussions about SNI with android on stackoverflow and elsewhere which indicate, that it might be possible but probably not with the DefaultHTTPClient class.
I believe your issue is that you are using SSL on two different domains, that share the same IP address.
Since SSL is done PRIOR to the web services (HTTP), the SSL cannot know if the user is accessing design.mysite.co.uk or mysite.co.uk, it just knows it is accessing site on IP A, so it is handing the certificate it has, which if I read correctly is for mysite.co.uk.
Then the HTTP session starts, and the browser confirms whether the provided certificate matches the URL, when you access design.mysite.co.uk it doesn't, when you access mysite.co.uk it does.
Solution:
Get another IP address and provide it to one of the sites, thus splitting your web site's SSL access to two separate IP addresses, which each will provide a difference certificate.

Categories

Resources