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

Ways to retrieve a list of identifiers from arrays at both initial and subsequent levels

I'm currently dealing with a JSON/JavaScript structure that looks like this: { "comments": [ { "id": 1, "content": "lorem ipsum", "answers": [] }, { "id" ...

Adjust the JSON format that is retrieved from an Ajax call

I am working with a JQuery plugin that includes the following code snippet: transformResult: function(response, originalQuery) { } Within this function, I have the task of converting Json data from the originalQuery to the response format: [ { "Id": ...

Node.js Express Issue: Module Not Found

Having trouble launching an express app in docker with node 10.9.0 due to an import problem: root@e85495ae1c9e:/usr/app/backend# node app.js internal/modules/cjs/loader.js:583 throw err; ^ Error: Cannot find module '/usr/app/backend/models/todo&ap ...

How can we create karma unit tests specifically tailored for Angular applications?

In the past, I utilized Jasmine and Karma to conduct unit tests on my AngularJS application. I am curious to find out if there is a method for dynamically generating Karma unit test files. Can someone advise whether it is beneficial to auto-generate unit ...

Guide on showcasing an alert notification when the data is already existing within an array through javascript

Need help with displaying an alert message in JavaScript for duplicate values in an array? var names = []; var nameInput = document.getElementById("txt1"); var messageBox = document.getElementById("display"); function insert() { names. ...

How can you access the query in Next.js API when req.query is initially set to undefined?

Is there a way to compare the value of req.query with the cookies on the site, even when req.query is undefined upon initial load? How can this be addressed? export default async function handler(req, res) { const { method } = req; const userId = req ...

Creating a unique custom view in React Big Calendar with TypeScript

I'm struggling to create a custom view with the React Big Calendar library. Each time I try to incorporate a calendar component like Timegrid into my custom Week component, I run into an error that says react_devtools_backend.js:2560 Warning: React.cr ...

Whenever I find myself being redirected to the login page, my goal is to eliminate the bottomTab from view

I'm looking to eliminate the bottom tab when I land on the login page, even though I've set it up for all pages. However, whenever I click on the login button, the tab remains visible. Here is my current code: import React, { useContext } from & ...

What is the best way to reset the state to null when the input field is blank?

After setting some inputs with a state of null, I noticed that when the end-user types something and then deletes it all, the input reverts back to an empty string. How can I adjust the state so that it returns to null? I seem to be encountering an issue ...

Issues encountered when trying to execute npm start: "The function this.htmlWebpackPlugin.getHooks is not recognized."

My background in web development is weak, and I'm facing a challenging situation. I had to take over the work of a colleague who left, and now I'm trying to finish the site we were working on. Since then, I've been learning about web develop ...

The disappearing act of Redux state after being added to a nested array

When attempting to update my redux state, I am facing an issue where the state disappears. My approach involves checking for a parentId - if one exists, I insert the payload into the parent's children array. However, if no parentId is provided, I simp ...

Divide a string into separate array items where a specific character is found

Within my sentence are several characters (~). I want to split the text before each ~ into an array item, and then add a <br /> tag at the end of each item. I attempted using the replace method but it only worked for the first ~ and disregarded the ...

Is it feasible to generate a fixed lighting effect overlay with HTML and CSS?

Is it possible to incorporate a static lighting effect overlay using HTML/CSS? My project consists of an HTML5/JS app with a top navigation bar and a series of cards that are transitioned through using swipe gestures. These cards are displayed in gray ove ...

Combine several pages from PDF files into a single document

I am currently working on developing a small electron application that combines multiple PDF files or pages into one larger page to help save paper when printing several CAD drawings. Essentially, I am looking for a cross-platform solution similar to the ...

Effective methods for eliminating timezone in JavaScript

I need to display the time and format {{transaction.submitTime | date:'yyyy-MM-dd HH:mm:ss Z'}} Currently, it displays 2015-04-23 02:18:43 +0700 However, I would like to show the time without +0700, where the hour will be incremented by 7. Is ...

Exploring Javascript bugs in Visual Studio (or any other JS debugger)

I am currently working with a .js file that is executed using cscript.exe and not in a browser environment. I am aware that I can use the //X parameter with cscript.exe to trigger a debugger selection prompt. This works well when choosing "Visual Studio 2 ...

What's the best way to refresh append() functionality within a modal? I'm currently working with NODE JS and AJAX and

Whenever I click the modal, the append() calls are adding HTML content. But if I try to use empty() or html(), the modal stops appearing altogether. What is the correct approach to creating this modal? function loadModalContent(id) { $('#myModal& ...

Switching from file:// to http:// in Angular / Ionic is a necessary step when incorporating external scripts like the Disqus directive into your project

Currently, I am attempting to incorporate the disqus directive into my project. The documentation for this directive can be found here. However, I have encountered some issues due to the particular setup of my application. There is a line in the script wh ...

Is there a way for me to verify if a number is represented in exponential form?

Is there a way to determine if a number is in exponential form? I encountered a situation in my code where normal integers are being converted to exponential notation when adding or multiplying them. For instance, performing the operation 10000000*1000000 ...

How can you retrieve the `categoryIds` key within an object that holds an array of mongodb's `ObjectId(s)` as its value?

In my Node.js code, I have the following: var getQuestionsByUserId = function (config) { var query = { _id: ObjectId(String(config.userId)) }; var projection = { categoryIds: true, _id: false }; var respondWithCategories = function (error, doc ...