The server returned a status code of 400 when receiving an empty JSON body through

Could someone please help me troubleshoot this $http.post call? I'm getting a bad request and the server is receiving an empty json body.

var data = JSON.stringify({

            "Name": $scope.device.ChildName,
            "Serial": $scope.device.Serial

        });

        console.log($scope.device.Serial);
        console.log($scope.device.ChildName);
        console.log(data);

        $http.post('http://141.135.5.117:3500/device/register', data, { headers: headers })
        .then(function(response){
            console.log(response);
            console.log(headers);




        });

Here are my headers:

var headers = {
            "Content-Type": "application/json;" ,
            "Authorization" : JWT

    };

Just a note: JWT is being used for Authorization.

Thank you!

Answer №1

Success!

For some reason, removing the Content-type argument from the headers fixed the issue.

I recall reading that HTTP post is typically done in JSON format by default. Could it be that overriding this in the headers was causing errors?

Answer №2

To resolve the issue, try sending the data without stringifying the object when using 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

Delay in Ionic list item navigation

As I continue to build my app using "$ ionic start myApp sidemenu" and deploy it directly to Android, I've noticed a significant delay when tapping on the playlist page, such as when selecting "Indie". It feels like there is a 300ms lag before the pag ...

Conducting AngularJS / Jasmine tests on a project's built or source versions

Currently, I am in the process of developing a project using AngularJS that consists of multiple applications within one project sharing components and modules. Additionally, I have implemented a Grunt build task to "optimize" the sources into a bundled ve ...

Unable to access a frame inside an iframe and frameset using JavaScript when both domains are identical

I am attempting to use JavaScript to access an HTML element within a nested frame in an iframe and frameset. The structure of the HTML is as follows: <iframe id="central_iframe" name="central_iframe" (...)> <frameset cols="185, *" border="0" ...

What steps do I need to take to create a dynamic rowspan within Vuetify?

I am currently working on creating a table that resembles the image provided in the link below. https://i.sstatic.net/xWa1I.png I understand that I can achieve this by using nested data and multiple iterations with the help of the template feature offere ...

Retrieving JSON data from embedded documents in Mongoid with Rails 4

I am looking to extract all embedded documents from a parent document and return them as a list of JSON elements. Here is an example of the document structure: class Parent include Mongoid::Document field :name, :type => String embeds_many :kids c ...

Using the immutable update pattern with nested data in React

In Redux, it is emphasized that in order to update nested data, every level of nesting must be copied and updated appropriately. // changing reference in top level const newState = {...oldState} newState.x.y.z = 10; setState(newState) // or updating refer ...

Looking for a node.js IDE on OS X that can display JSON objects similar to how they appear in the console of Chrome or Firefox?

While using Google Chrome, I noticed that when I console.log(object), a detailed view of the object is displayed in the console instead of just a string representation. This feature is incredibly useful. Unfortunately, when running node.js scripts on my ...

software tool for managing state transitions

Can anyone recommend a superior javascript library for workflows? Right now, I'm utilizing Joint JS, but I require something with a more visually appealing interface (users tend to prefer that). ...

The dropdown feature is malfunctioning. (Using Angular 8 and Bootstrap)

I'm encountering an issue with displaying a dropdown and its options using the bootstrap directive 'ngbDropdown'. When I follow this example from the documentation: <div ngbDropdown class="d-inline-block"> <button class="btn ...

Changes in query parameters on NextJS navigation within the same page do not activate hooks

When utilizing NextJS without SSR, I encountered an issue with basic navigation using different query parameters. Upon the initial arrival on the page/component, everything seems fine as the component gets mounted and URL params change accordingly. However ...

AngularJS Bootstrap Select Generates Additional Dropdowns

Currently, I am utilizing the bootstrap datepicker from , and it functions perfectly when accessed via a desktop browser. Additionally, my project incorporates AngularJS. The snippet of code in question is as follows: <div class="form-group" ng-repeat ...

Can someone explain the significance of receiving a TypeError when trying to access properties of null (specifically 'useRef') in a React application?

I encountered an issue while working on a React project...the browser console displays the following error. What does this mean? And how can I resolve it? react.development.js:1545 Uncaught TypeError: Cannot read properties of null (reading 'useRef ...

Is your Vue.js chart malfunctioning?

I have been experimenting with chart.js and vue.js. The component I created is called MessageGraph, and it is structured like this (with data extracted from the documentation): <template> <canvas id="myChart" width="400" height="400">< ...

Searching for the search parameter in the Wordpress admin-ajax.php file. What could it

Just diving into the world of php and wordpress. Are there any search parameters I can include in admin-ajax.php? Here are the parameters in the ajax post; action: rblivep data[uuid]: uid_search_0 data[name]: grid_small_1 data[posts_per_page]: 8 data[pagin ...

Output the keycode to the console repeatedly

I'm currently facing a minor mental obstacle: I have a javascript function embedded in html that displays the keycode when a key is pressed. It's connected to a function that provides detailed information about the character and keycode being pre ...

Issues with Videojs Responsive Lightbox Functionality

I am looking for a solution to display VideoJS in a lightbox while keeping it responsive. I came across this helpful code snippet: https://github.com/rudkovskyi/videojs_popup. It seemed perfect until I tried using it with the latest version of Videojs and ...

I'm struggling to figure out how to specify the data type for storing an array of objects in a variable using React.useState

I am currently working on extracting values from an .xlsx file using the SheetJS library. Below, I will provide the code snippets, errors encountered, and the different approaches I have attempted. Data extracted from var dataToJson: (6) [{…}, {…}, { ...

Tips for validating a URL in Cypress without having to actually visit the page

Is there a way to verify the URL without actually opening the page? The application is built on AngularJS and uses the ng-click method ($state.go) for navigation. I've researched Cypress stub and intercept options, but haven't found any solutions ...

Having trouble finding module: Unable to locate 'fs' - yet another hurdle with NextJS

Trying to access a JSON file located one directory above the NextJS application directory can be tricky. In a standard JavaScript setup, you might use the following code: var fs = require('fs'); var data = JSON.parse(fs.readFileSync(directory_pat ...

Using AngularJS and PHP, create a datepicker that dynamically blocks dates from a database

After extensive searching on the internet, I have yet to come across a datepicker that can dynamically check in a database for available dates in the current month. Does anyone know of any such datepicker? Alternatively, do you have suggestions for an Angu ...