`Inconsistencies between Postman and AngularJS service responses`

When I make a call to the endpoint using Postman, I receive this response:

https://i.stack.imgur.com/pH31G.png

However, when I make the same request from my AngularJS service defined below:

this.login = function (loginInfo) {

    return $http({
        url: 'http://localhost/igt/api/public/signin',
        headers: {
            'Content-Type': 'Application/json'
        },
        method: 'POST',
        user: {
            name: "nick",
            password: "password"
        }
    })
    .then(function(response) {
        console.log(response);
    }, function (err) {
        console.log("err:");
        console.log(err);
    });
};

The output in the console looks like this:

https://i.stack.imgur.com/v0cDG.png

It shows the following response:

{
  "data": null,
  "status": 400,
  "config": {
    "method": "POST",
    "transformRequest": [
      null
    ],
    "transformResponse": [
      null
    ],
    "jsonpCallbackParam": "callback",
    "url": "http://localhost/igt/api/public/signin",
    "headers": {
      "Accept": "application/json, text/plain, */*"
    },
    "user": {
      "name": "nick",
      "password": "password"
    }
  },
  "statusText": "Bad Request",
  "xhrStatus": "complete"
}

What could be causing this difference?

Answer №1

Discover the various properties of the config object to customize your HTTP configuration

method – {string} – Specify the HTTP method (e.g. 'GET', 'POST', etc)
url – {string|TrustedObject}
params – {Object.<string|Object>
data – {string|Object}
headers – {Object}
eventHandlers - {Object}
uploadEventHandlers - {Object}
xsrfHeaderName – {string}
xsrfCookieName – {string}
transformRequest – {function(data, headersGetter)|Array.<function(data, headersGetter)>} – 
transformResponse –
paramSerializer
cache
timeout
withCredentials - {boolean}
responseType - {string}

For more information, click here

This might be the issue,

user: {
         name: "nick",
         password: "password"
      }

Answer №2

When using the Postman tool, make sure to provide the following input:

{
 user:{
 name:"",
password:""
}
}

The input you are currently sending is incorrect:

{
    name:"",
    password:""
    }

To resolve this issue, update your AngularJS code as follows:

user: {
   user : {
name:"nick",
password:"password"
}
}

This adjustment should fix the problem.

Additionally, ensure that you modify the header to:

'Content-Type': 'application/json'
from
'Content-Type': 'Application/json'

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

Is it possible to apply (max / min) to a mongoose string?

Is it possible to limit the maximum string length to 5 characters using this method? Or is this functionality only available for numbers? someString: { type: String, max: 5 }, Thank you! ...

Is it possible to utilize EmberJS or other frameworks without the necessity of setting up its server?

I am in search of a JavaScript framework that offers the following features: MV* Well-structured HTML file as template Fast rendering (possibly using virtual DOM) Ability to combine and be compatible with other plugins or libraries Edit on tablet IDE app ...

Building a React.js application and fetching information with Ajax

In my quest to create a high-speed React.js application that functions as a game, I find myself in need of displaying real-time data. However, the traditional method of loading this data from the server using Ajax doesn't quite align with the reactive ...

An async function cannot be used as a Constructor

I am in the process of creating a constructor function using JavaScript. This constructor needs to be asynchronous because I am utilizing the Phantom JS module for data scraping. As a result, an asynchronous function must be used to scrape data through Pha ...

When using Angular $http.post, encountering issues with the 'Access-Control-Allow-Origin' header

I have developed two applications using nodejs and angularjs. The nodejs app contains the following code: require('http').createServer(function(req, res) { req.setEncoding('utf8'); var body = ''; var result = '&a ...

Having trouble retrieving data using a custom URL in Axios with ReactJs

My knowledge of Reactjs is still new and I am currently working on a project using nextjs. I have a component called Trending.js that successfully fetches data from the URL "https://jsonplaceholder.typicode.com/users". However, when I try to change the U ...

Issue encountered with the latest version of Selenium web driver when using Firefox browser

I am currently using Selenium jar version 3.3.1 with Firefox 43.0.4 and Eclipse Mars.2 Release (4.5.2). When I execute the following code: import java.util.List; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selen ...

Adding Roles Using Discord.js - A Simple Guide

I'm currently working on a Discord bot using Discord.js, and I am trying to implement a feature where users can use a command to assign themselves a role. However, despite my best efforts, I am unable to get this functionality to work. In my bot' ...

Utilizing Angular to incorporate a JSON file within a form

Recently, I've delved into the world of angular and node.js. My current challenge involves populating html forms with content from a json file based on dropdown selection. While I've successfully achieved this, I encounter an issue when manually ...

Ways to activate auto completion without using a string

Can anyone assist us with the tinymce editor? We have implemented an auto completion feature using a plugin from TinyMCE's documentation, but we are having trouble changing the triggering behavior. Currently, it only suggests options when "@" is typed ...

Counter cannot be accessed once it has been updated

When I click a button, an interval should start. The issue is that I'm unable to access the value of counter. The goal is for the interval to stop when the counter reaches 5. Here's an example: let interval = null; const stateReducer = (state, ...

Error message "Undefined is not a function" occurred while using jQuery's .replace and scrollTop functions

I'm having issues with the scroll function in my code. It doesn't seem to be able to locate the ids in my HTML, even though I can't figure out why. I had a previous version that worked perfectly fine (unfortunately, I didn't save it D:) ...

What methods can be used to ensure a required minimum delay time between function executions?

For my node function, I am aiming for a specific execution delay of around 5 seconds. The minimum delay needs to be implemented within the function itself, not externally, so external users are unaware of the delay. Therefore, I cannot rely on modules l ...

Generating a new root in React 18 results in numerous rounds of rendering and execution

Every time I attempt to run this code in React 18, it seems to render multiple times unlike React 17 where it only executes once and functions properly. How can I modify the code so that it only runs once? Is there a specific reason for the multiple execu ...

What is the best way to establish *object keys* with AngularJS models?

I have developed a tool to easily create a JSON-schema that looks like this: { "type": "object", "properties": { "myFirstProperty": { "type": "integer" } }, "title": "MySchema", "description" ...

Are there any potential methods for converting HTML to PDF within a Cordova Angular JS and UWP app using jQuery? I encountered an error stating that 'blob:ms-appx-web' is not permitted to load

view image here I encountered this issue: SEC7134: Resource 'blob:ms-appx-web://mysiteurl/3d5c0f51-04e2-4944-bf3e-4ea19185511c' not allowed to load If anyone has a solution, please help us in resolving this problem. Below is my code snippet ...

Are there any limitations imposed on keydown events in JavaScript when attempting to modify the browser's

I attempted to implement a JavaScript keydown event that would refresh the page, but unfortunately, it did not function as intended. Interestingly, the same code works flawlessly when triggered by a button click event. I'm in search of a solution to r ...

What is the best way to incorporate a generated ID into the datepicker() function whenever a button is clicked?

I'm looking to dynamically generate a row of input fields with unique IDs every time the "add another flight" button is clicked, similar to the functionality seen on destina.us. Additionally, I need to incorporate these generated IDs into the jQuery U ...

Optimal method to refresh v-for when updating route in Vue.js seamlessly without having to manually reload the page

What is the best approach to re-render a v-for loop in my Vue.js application when switching to another route? In my scenario, I am using Vuex, vuex-persistedstate, and moment for saving data in localStorage and displaying timestamps like "a moment ago". ...

How to easily retrieve additional data and update a document using Meteor

I'm feeling a bit lost on the best approach for obtaining additional data, particularly using an API, and adding it to the existing list. Imagine we're implementing either an infinite scroll or a 'load more' button, when that action oc ...