I have an android project which uses cordova. I am firing some http requests. It works fine. But when I generated signed apk, the firing is done as https requests. Android studio does not support this type of requests. How can I find an alternate solution for this? I tried Phonegap Android app ajax requests to HTTPS fail with status 0 but this answer is outdated as Cordova 4.0.0 does not have this method .Please help me out.
#Nevin, an alternative in HTML5 is to leave out the http (or https).
Instead of this:
https://domain.com/request/
Write:
//domain.com/request/
This is support by many browsers. It is a way to fix a common problem, where the javascript is on a secure connection, but the webpage is not.
Related
My API's are working fine in applications but if I'm trying to call API with web so API's are not working
API's are implemented with dio (https://pub.dev/packages/dio)
Welcome for the improvements and thanks in advance for solutions and suggestions.
This is a CORS (cross-origin resource sharing) issue. You need to enable the CORS request on your server-side to fix this. Depending on your setup, you won't be needing to make changes on the client app.
Common workarounds made here for development builds is by disabling security using --disable-web-security argument when the app is run.
I have downloaded a third party apk and I am trying to intercept and view API calls from this app. When using fiddler and other network analyzers android did not let me use the apps behind a proxy. Now I am tying to use android studio's network profiler, but i am not being able to wrap my head around how it works. Is there a known work around to intercept http requests from an arbitrary apk?
Use NetCapture tool. If the App is available to only a particular region than you might have a problem but otherwise you shouldn't have any problem intercepting it. And one other thing if the server is using https connection than you will have encoded json which you have to decode the json.
Firstly I would like to thank all the experts here on stackoverflow, by reading questions asked and looking at example code and reading the answers i have been able to get to this point. Thank you once again!
I have been spending hours and hours searching for a solution, I’ve read through many posts on this issue. It’s seem this is a issue a lot of others are/has been struggling with.I would highly appreciate any more advise or tips if somebody can assist in this frustrating issue.
All my development are done on my local machine. (Win 7, Visual Studio 11beta)
A WCF Service is hosted in IIS Express on its own port or IIS 7.5 (.Net Framework 4.0)
Second Web Application with only Html5/jQuery is hosted in IIS Express on a different port.
Using Eclipse 3.7.2 with Android SDK 17 also on my local machine.
Its seem all the software are functioning properly.
Android Emulator is working, Phonegap/Cordova library is installed, etc.
I am using Android 4.0.3 with Cordova 1.6.0
I am asking assistance to find out why my phonegap emulator ajax call won’t go through to my WCF REST Service. I don’t have a actual android device now to test the program on at this moment therefore I must use the Emulator.
Some more detail:
I have a WCF REST Service developed in .Net receiving & sending in JSON and JSON-P.
I have tested this with a second web application on a different port to make sure cross domain calls are allowed.
I have also used the RESTclient plugin for Firefox and can use it to make JSON and JSON-P calls successfully. [ http://restclient.net/ ]
So I am sure the WCF Service is working as it should. There shouldn't be any cross domain issue.
When I take the Html file with jQuery that I know is working within Visual Studio, to eclipse, copy into phonegap app, I try to make a basic call to my WCF server and I am unable to connect to the server.
I have changed the URL from [http://localhost:50425/LoginService.svc/GetData] to [http://10.0.2.2:50425/LoginService.svc/GetData]
according to android documentation : [http://developer.android.com/guide/developing/devices/emulator.html#networkaddresses]
I have created an allow all whitelist with the following setting:
[ access origin="*" ]
within the cordova.xml file. See: [http://professionalaspnet.com/archive/2012/05/15/Whitelisting-Domains-in-Cordova-_2800_PhoneGap_2900_-Android.aspx]
The correct permissions have been set inside the AndroidManifest.xml file according to [http://docs.phonegap.com/en/1.8.1/guide_getting-started_android_index.md.html#Getting%20Started%20with%20Android]
When I initiate the call, I use $.ajaxSetup error function to trap network error etc. and display with alert the error message. Used console.log() to make sure it passes this function without a error.
When the call actually happens, I receive a "Bad Request - Invalid Host Name. HTTP 400. The request hostname is invalid."
If the call would have been successful, I use breakpoints inside Visual Studio to know for certain the call has been made and see the request coming through.
Is there any other ways to test from emulator if I can access the "external" host? In this case to make sure emulator actually can find the service?
Is there any tools or other configuration settings that needs to be done?
I have even deleted my emulator and created a new one but it still fails to connect to the WCF Service.
I would really like this to work, would like to build a complete phonegap application but can’t continue if I can't make a call to a web service.
Any advise would be greatly appreciated.
PhoneGap is really just a wrapper for html/css/js webpages with a js library for accessing phone specific functionality, which can be compiled to multiple native mobile platform apps.
So this is really not a PhoneGap issue...
You say you are using JQuery to query your web service, if you can open the html file which fires of the request in your normal browser window, and everything works fine. The problem is not with the code, but with the Emulator you are using, maybe some miss configurations idk.
Okay if that still fails, you are most likely pointing to the wrong/no IIS Instance.
If you have two IIS Instances running on port 80 idk how that will behave, but i don't think that will work very well, my guess is that one of them will override the other one.
So if you are hosing your webservice on IIS 1, but IIS 2 overrides IIS 1, then you will never reach the webservice, and get the error you get.
So when you changed to point to the other IIS Instance, it started working again.
I am making an Android application in PhoneGap. What I'm trying to do is let the application talk to my Node.js server through WebSockets. My Node.js server uses Socket.IO which automatically falls back to polling when I open the application up, in contrary to the desktop Chrome application which happily opens up a WebSocket and communicates through it just fine.
I've read this blogpost about integrating the actual WebSocket API with Phonegap. The problem there is that I'm not overriding 'onConnect, onMessage' functions manually, instead Socket.IO does all that for me.
Is there some way to integrate WebSockets into my Android Phonegap application?
Short answer: Cordova WebView doesn't support WebSockets and socket.io doesn't connect to standards-based WebSocket clients.
For your client, it still appears that if you want real websockets, you need to use a Cordova plugin that is specific to an Android build or an iOS build. Try this search, which includes anismiles repo for an Android plugin, the same blogger referenced by the OP.
So with that in mind, socket.io will not work for your server. Unfortunately, socket.io server does not support connecting to clients with an Html5 standards-based websocket connection, you have to use their client library. As you've seen, you can't use their client library in Cordova...well you can, it'll just fallback to polling.
So now your websocket client is a standards-based Cordova plugin, you need a server that supports a standards-based websocket connection. You should take a look at SockJs, Worlize, Miksago, or Einaros. There are others. I'm currently using Worlize.
Another thing to keep in mind is that there is a short list of cloud hosts currently supporting true websocket connections. I recommend DotCloud or Nodejitsu.
If this answers your question please click the check mark :)
Updating the answers, this plugin works with socket.io and it's much easier to use (PhoneGap 3.x only).
https://github.com/mkuklis/phonegap-websocket
This repository will be integrated in phonegap very soon (at least it sounds like that in the readme)
It also also provides the steps for making web sockets work in phonegap / android.
Take a look: https://github.com/anismiles/websocket-android-phonegap
Here is another websockets Android client, that I am currently evaluating.
http://jwebsocket.org/mobile/android/android_part1.htm
I'm afraid I have no idea if it will be useful to a phonegap project, not being familiar with it.
Phonegap would need to allow you to incorporate an external java library into your project and you would need to build an interface for it in java.
Is it possible to set up Firefox to allow JSON/Ajax calls to my server
from a client html page loaded using the file:// protocol??
I am building a phonegap application which is loading web pages using
the file:// protocol and therefore XSS/XDS sandboxing rules don't
apply. This is cool! Unfortunately, I can only get this to work from
my Android Emulator (see below for setup). It does NOT work under
Firefox running on my Vista client machine. This is disappointing
because I have grown used to using Firebug on the client to debug my
application.
FYI, The following setup works fine (but doesn't allow Firefox/Firebug
debugging)...
Server: Ubuntu running on Virtual Box, Eth0 in Bridged mode, node.js
returning a JSON messages)
Development (Host) Machine: Windows Vista running Eclipse with Android
SDK and Phonegap stuff loaded
Client: Application (.apk) deployed to the standard Android Emulator
Edit: I eventually gave up on this and used JSONP :/
I know you like Firefox but you could try Safari on Windows since it allows cross domain from file:// and it has good tools in the form of web inspector.
You could also try Sleight (https://github.com/alunny/sleight). which is a very simple proxy written in NodeJS specifically for PhoneGap.
It looks like pre-Firefox 3, you could configure Firefox to allow cross-domain requests but not anymore.
I have two suggestions that you could explore:
If you have control over the server, you could set the Access-Control-Allow-Origin header in your response from the server (temporarily) to * to allow anyone to get data from your URL (remember to remove that later!).
Use a proxy. It's pretty easy to set up Apache as proxy+reverse proxy for a limited number of URLs. This avoids the need to touch your server-side code and is probably the quicker, more reusable and less error prone of the two options.
http://www.apachetutor.org/admin/reverseproxies
http://httpd.apache.org/docs/2.0/mod/mod_proxy.html
Use Chrome. Its debug module is nearly Firebug in terms of quality and if you open it with
chrome.exe -allow-file-access-from-files
...it will allow cross-file access.