Strange response received from $http GET request on Android device running Crosswalk

I am attempting to retrieve data in JSON format from an API using AngularJS. The process is successful on iOS and desktop browsers, but I'm encountering a strange response when trying it on my Android device. The request code looks like this:

$http({
    url: baseUrl, 
    method: "GET",
    headers: {
          "Content-Type": "application/json"
    },
    params: {
          authKey: myAuthKey,
          id: myId,
          format: "json"
    }
})
.success(function(data, status){
     console.log("Success", data); // The output differs on Android
     orderData(data);
})
.error(function(data, status){
     console.log("Error");
     console.log(data,status);
});

The request always succeeds and returns an object as expected on iOS and desktop browsers. However, when I check the data on my Android device, the result is unexpected and appears to be HTML code related to a router:

>     Success <html>
>     <head>
>     </head>
>     <body>
>     <script>
>     var wwwurl='www.mywifiext.com/welcome.htm';
>     function check_mobile_device()
>     {
>     if(navigator.userAgent.indexOf("iPhone") != -1)
>     return 1;
>     else if(navigator.userAgent.indexOf("Android") != -1)
>     return 1;
>     else if(navigator.userAgent.indexOf("Windows Phone") != -1)
>     return 1;
>     else if(navigator.userAgent.indexOf("iPad") != -1 )
>     return 0;
>     else
>     return 0;
>     }
>     if(check_mobile_device() == '1')
>     top.location.href="http://www.mywifiext.net/mobile_welcome.htm";
>     else
>     top.location.href="http://www.mywifiext.net/welcome.htm";
>     </script>
>     </body>
>     </html>

This unusual HTML response seems to be linked to a specific router. I have tested it on various Wi-Fi networks and even with the device's 3G connection.

I recently integrated Crosswalk into my project, which utilizes the cordova-plugin-whitelist. Could this integration be causing the issue? Or is it possible that there is a bug on the API side?

EDIT: Reverting back to the default browser resolved the issue. But why did it happen? How can I make it work with Crosswalk?

Answer №1

Give it a shot!

Let's start by setting up the URL we want to make a request to:

String url = "http://my-json-feed";

Now, let's create a JsonObjectRequest and pass in the necessary parameters:

JsonObjectRequest jsObjRequest = new JsonObjectRequest
    (Request.Method.GET, url, null, new Response.Listener<JSONObject>() {

Override
public void onResponse(JSONObject response) {
    Log.v("Response: ", response.toString());
}
}, new Response.ErrorListener() {

@Override
public void onErrorResponse(VolleyError error) {
    // Handle any errors that occur during the request
}
});

Answer №2

The issue at hand is not related to your code.

If you find yourself in an open WiFi network that requires authentication through an HTML page, when you try to access resources via HTTP without being authenticated on the network, you will be redirected to a welcome page.

A potential solution:

Simply open a web browser and visit any webpage. You will then be redirected to the welcome page (which essentially acts as the page you downloaded with your $http.get()). Here, you can enter your network access credentials and agree to the terms. Subsequently, your Cordova application should function as expected.

Consideration for your users:

In similar scenarios, offering error handling mechanisms could prove beneficial for your users. An option could be to include an HTTP interceptor that manages non-JSON responses, providing guidance to users on troubleshooting their network and logging into the access point if necessary.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Functionality of $rootScope.$broadcast with Dual Arguments

I've been reading through this interesting article: https://medium.com/opinionated-angularjs/techniques-for-authentication-in-angularjs-applications-7bbf0346acec#.rlvow9x66 In an attempt to adapt their AuthInterceptor, I made modifications to handle ...

Show specific keys in the JSON response

Creating a straightforward API using express and sqlite, I aim to customize my GET request to only exhibit specific keys in each JSON object within the response. The snippet below showcases my current code: router.get('/cars', (req, res) => { ...

typescriptCreating a custom useFetch hook with TypeScript and Axios

I have a query regarding the utilization of the useFetch hook with TypeScript and Axios. I came across an example of the useFetch hook in JavaScript, but I need help adapting it for TypeScript. The JavaScript implementation only handles response and error ...

Is it possible to save edits made to CKEDITOR by clicking a button located outside of the editor?

I am having an issue with inserting HTML code into my CKEDITOR. I have a button on the page that, when clicked, calls: editor.insertElement(link); After inserting the HTML code correctly into the editor, any changes made (such as clicking the 'show ...

Having several horizontal scrollbars at once on a single webpage

I stumbled upon a great example showcasing how to scroll a div on my page: Check out this Codepen - https://codepen.io/zheisey/pen/xxGbEOx Although, I am looking to extend this functionality to allow multiple divs to scroll together. Any suggestions? I ...

Having trouble selecting the autosuggest option using Python's Selenium WebDriver?

I am trying to select the "service-instance called 86... --Schema" element from the UI snapshot (link provided below) using Selenium, but so far I have not been successful. Any suggestions would be greatly appreciated. Thank you. So far, I have attempted ...

Tips for creating a binding between an HTTP service and a variable in AngularJS that adjusts when the server data is modified

Using an http get request in angular to extract data into an object with the users currently connected to my app requires refreshing the information every time for binding to the scope. To achieve this, I implemented a method to refresh the data from the a ...

Why is my custom function failing to operate on an array?

My function is created to organize and remove duplicates from a provided array. Below is an excerpt of the code: Bubble Sort - function organize(postsCollection, type, direction){ let target = postsCollection[0][type]; let swapp = false, ...

Using Javascript/JQuery to apply pixel values in CSS styling

Recently, I've come across a discrepancy between two different ways of accessing CSS properties in jQuery: <foo>.css('marginTop') (which I always assumed was the standard notation) and <foo>.css('margin-top') (which ...

Issues with navigating jQuery UI links while offline in Google abound

Hello, I am a newcomer to jQuery and I am facing an issue with my code. I added the <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script> but for some reason, my jQuery is not working. I have tried searching ...

Tips for choosing an <li> element with JavaScript

<style> .sys_spec_text{} .sys_spec_text li{ float:left; height:28px; position:relative; margin:2px 6px 2px 0; outline:none;} .sys_spec_text li a{ color: #db0401; height:24px; padding:1px 6px; border:1px solid #ccc; background:#fff; dis ...

How to submit a form using AngularJS on an ASP.NET webpage

Having some frustrations with asp.net... I have a basic website with a form in my master page that needs to be server-side because of the controls I use. Now, I want to incorporate angularjs into a simple page on this site. My goal is to only submit the fo ...

the async function fails to run

fetchData = async () => { try { //Accessing data from AsyncStorage let car = await AsyncStorage.getItem('CAR') this.state.DatabaseCar=[]; this.state.DatabaseCar = JSON.parse(car); alert(this.state.Da ...

Does invoking a regular function in $q behave synchronously or asynchronously?

* // In this scenario, suppose that variables `$q` and `okToGreet` are accessible in the existing lexical scope. They might have been delivered or passed as parameters. // Carry out an asynchronous task, resolving or rejecting the promise accord ...

Unable to attach the script to recently added DOM elements

After spending considerable time working on this, I'm still unable to figure it out. You can find the page I am referring to at: The "show more" button at the bottom triggers additional posts to be displayed on the page using the following script: ...

Issues with ng-model disappearing while using ng-include (AngularJS)

Currently working on an Android app with Ionic and AngularJS. Using ng-include to include HTML content in the app's pages. checkbox.html: <ul> <li ng-repeat="opt in $parent.checkboxOptions"> <h4> ...

Divider displayed between images in Internet Explorer 8

On my website, I have arranged four images in a square using the code below: <div id="tempo_main"> <div id="tempo_content"> <div style="text-align: center;z-index: 3;position: absolute;right:350px; left:350px; t ...

Using Selenium to interact with drop-down lists using div tags instead of select tags

As a newcomer to automated testing using Selenium Web Driver, I am struggling to test drop down lists for the location type without relying on the select command. The element in question is enclosed within a div tag. I attempted sending keys but that meth ...

Retrieving decimal value from a given string

Currently, I am working with Google Maps and encountering an issue with distance values being returned as strings like 1,230.6 km. My goal is to extract the floating number 1230.6 from this string. Below is my attempted solution: var t = '1,234.04 km ...

A step-by-step guide on initializing and setting a cookie value with expiration

Below is the code I have added. Can someone please help me locate the bug? Here is the code snippet: $_SESSION['browser'] = session_id(); setcookie($expire, $_SESSION['browser'], time() + (60 * 1000), "/"); echo "Value is: " . $_COO ...