`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

Preventing users from inputting the symbols "+" or "-" in a React JS input field

Essentially, the input field should only accept values between 1 and 999 Input Field : <input type="number" value={value} onChange={this.props.onViltMaxUserChange} min="0" max="999" /> onChange : onViltMaxUserChange = _.throttle(e = ...

Attempting to configure a discord bot. Can anyone help me identify the issue?

I've been working on setting up a discord bot using Discord.js. I have all the necessary tools installed - Node.js, Discord.js, and Visual Studio Code. I've even created an application and obtained a token for my bot. However, I'm running in ...

Struggling with the navbar-toggler in Bootstrap 4 Beta 2?

As part of my Bootstrap practice, I have implemented a navbar on my webpage. However, I am facing issues with the nav-bar toggler not working for small screens and the icon navbar-toggler-icon not appearing. Below is my current navbar code: <nav class ...

Troubleshooting AngularJS: Diagnosing Issues with My Watch Functionality

I need to set up a watch on a variable in order to trigger a rest service call whenever its value changes and update the count. Below is the code snippet I have: function myController($scope, $http) { $scope.abc = abcValueFromOutsideOfMyController; ...

Attempting to extract data from a JSON object within a multidimensional array

Looking at the JSON structure that I need to work with: [ { "result":"OK", "message":"Display", "value":200, "rows":29 } , [ { "personID":1, "img_path":"/1234/", "img ...

Load the iframe element only when the specified class becomes visible within the container div, without relying on jQuery

I am facing a unique challenge where the performance of my page is significantly impacted by loading multiple iframes. These iframes are contained within popup modals, and I would like to delay their loading until a user clicks on the modal. When the mod ...

Issues encountered when trying to install Angular 2 packages through npm in Visual Studio 2015 Update 2

I'm currently trying to integrate the latest angular2 quickstart files into a brand new ASP.NET Core 1.0 Web Application. Running VS2015 Update 2 - with Core 1.0 RC2 already installed To replicate this issue: Start by creating a fresh project usin ...

Shorten the content while preserving the HTML using JavaScript

When printing a string containing HTML links, I need to truncate the visible text while preserving the link structure. Simply using a substring method would disrupt the HTML tags in the string. I aim to display only 100 characters but also remove any inc ...

Dealing with errors when chaining promises in a react-redux application

This is related to a question asked on Stack Overflow about Handling async errors in a react redux application In my react-redux setup, I am facing a scenario where I need to chain multiple API calls upon successful completion of each. How can I achieve ...

Float and tap

Can someone assist me with my code? I have 4 identical divs like this one, and when I hover over a link, all the elements receive the same code. <div class="Person-team"> <div class="profile-pic-d"> <a cl ...

I am looking to consolidate my array of objects into a single object with distinct keys

Hey there! I'm looking to showcase the expenses for each category throughout the months of the year. Here's an example: {Month: "January", Food: 610, foodColor: "#063951", Others: 121, othersColor: "#C13018", …} Fo ...

Mix up table data cells using Javascript/jQuery

Can anyone provide me with some helpful tips? I'm really struggling with this. My Objective I aim to create a table with two columns ("name" and "rating"), consisting of 5 rows. 2 of these rows should have a random "rating" between 6-10 2 other ro ...

Parallax scrolling in all directions

Is there a resource available for learning how to program a website similar to the one at ? I am familiar with parallax but can't seem to find any examples that resemble what they have done on that site. ...

Preventing Redundancy in Angular 2: Tips for Avoiding Duplicate Methods

Is there a way I can streamline my if/else statement to avoid code repetition in my header component? Take a look at the example below: export class HeaderMainComponent { logoAlt = 'We Craft beautiful websites'; // Logo alt and title texts @Vie ...

Is it possible to develop an AngularJS application using a basic ASPX framework?

Is it possible to develop an Angular Js application within ASPX web forms while following a three tier architecture approach, including separate layers for the database and business logic? ...

Is it possible to transfer a variable from my javascript code to a jsp file?

Within a HTML file, I have created a variable in JavaScript consisting of an array with two entries - a latitude and a longitude. I am looking to use AJAX to send this variable and then utilize it in my JSP file to populate a form. Does anyone have any su ...

Creating a Node.js API with Firebase Backend

Hey everyone, I wanted to get some advice on a project I'm working on. I've read a lot about setting up Node/Express with Firebase, but I'm curious about potential challenges when it comes to building and scaling a custom REST API using Fire ...

Error: Unable to retrieve the value as the property is null

I'm a beginner in jQuery and I'm attempting to create a login form that displays a message when the user enters a short username. However, despite my efforts, the button does not trigger any action when clicked. Upon checking the console, it indi ...

Using jQuery Datatables fnReloadAjax successfully triggers a reload of the data, however, it

In my jQuery datatable, I am utilizing the code below to refresh the data: $(".unread-rows").click( function(e) { e.preventDefault(); message_table.fnReloadAjax("/letters/ajax/inbox/1"); message_table.fnDraw(); $(this).addClass("active").s ...

Determining the Existence of Duplicates in an HTML Table with Multiple Inputs Using JavaScript

After spending countless hours on research with no luck, I've finally come to seek assistance from you. In my form, I have an input field and a select field, along with a table generated using PHP from my database that displays team names and their r ...