The body of the POST request appears to be void of any

Whenever I make a request using curl or hurl, an issue arises. Despite req.headers['content-length'] showing the correct length and req.headers['content-type'] being accurate, req.body returns as {}.

Below is the Hurl test:

POST http://localhost:8080/v1/fragments
Content-Type: text/plain

[BasicAuth]
<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="95e0e6f0e7a4d5f0f8f4fcf9bbf6faf8">[email protected]</a>:password1
`This is a fragment!`

The equivalent command in curl is as follows:

curl -i \
  -X POST \
  -u <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea9f998f98dbaa8f857ebdedfefecffdebfbfecbaa58effbfbe2a3affbfeeefeebef24523fdaafeefaee53a2bfefaeec939cefabaaaf96acaabaabaaa09c0eaeaedaadedaed">{ann]&??)}</a>:password1 \
  -H "Content-Type: text/plain" \
  -d "This is a fragment" \
  https://localhost:8080/v1/fragments

Below is the React code where router equals express.Router():

router.post('/fragments', (req, res) => {
    let newuuid = uuidv4();
    res.location(`http://localhost:8080${req.originalUrl}/${newuuid}`)
        .status(201)
        .json(
            createSuccessResponse({
                fragment: {
                    id: newuuid,
                    ownerId: '11d4c22e42c8f61feaba154683dea407b101cfd90987dda9e342843263ca420a',
                    created: '2021-11-02T15:09:50.403Z',
                    updated: '2021-11-02T15:09:50.403Z',
                    type: req.headers['content-type'],
                    size: Number(req.headers['content-length']),
                },
            })
        );
});

Answer №1

Instead of using app.use(bodyParser.json()); when sending text/plain content, I should have used app.use(bodyParser.text());.

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

Step-by-step guide on setting up and utilizing the eth-auth (ethauth-server) library

Can you explain the purpose and usage of the eth-auth library? Additionally, could you provide instructions on how to incorporate the ethauth-server npm library into a node.js project? ...

npm encountered an error: invalid email address [email protected]

Once I updated my node installation using brew upgrade node: $ node -v v0.10.30 I ran npm update -g: $ npm -v 1.4.23 An error occurred when running npm ls -g: npm ERR! invalid: <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail ...

Removing a Dom element using stage.removeChild( )

When the number 6 is typed and entered into the game, the function correct() in the code snippet below determines what action to take. I would like to remove the DOM element gg (the equation 3+3=input) from the stage after typing 6 and pressing enter. How ...

Arranging and moving list elements without the use of jQuery UI (or any jQuery libraries at all?)

I have been searching for a JavaScript plugin that offers the same functionality as jQuery UI Sortable, which is the ability to drag and drop items to reorder them. In my case, these items are <li> tags. I prefer not to use jQuery UI because it is h ...

Transferring users from OneSignal to our custom database for sending notifications

Our team is currently in the process of transitioning our subscribers from OneSignal to a new service. We have exported the necessary endpoint, keys (auth and P256DH), and configured the VAPID keys of our new service account on our server. However, we ...

There seems to be an issue with Node.js/Express: the page at /

Recently, I've been working on some code (specifically in app.js on the server). console.log("Server started. If you're reading this then your computer is still alive."); //Just a test command to ensure everything is functioning correctly. var ...

AngularJS controller exceeding allowed complexity (SonarLint alert)

While utilizing SonarLint in Eclipse, I encountered an issue while working on an AngularJS application. Specifically, I was cleaning up a controller to improve readability when SonarLint flagged the following problem: The function has a complexity of 11 ...

How to Efficiently Process Large Files in Node.js using V8 Engine

Query Is there a way to load files larger than 1.1 GB into memory using node.js? Situation I am attempting to utilize topojson on node.js for converting GeoJSON files exceeding 1.1 GB into TopoJSON format. $ topojson -o outfile.json file_over_one_point ...

Is it necessary to delay until the entire page finishes loading in Selenium 3?

public boolean CheckPageLoadStatus(){ final ExpectedCondition<Boolean> pageLoadCondition = new ExpectedCondition<Boolean>() { public Boolean apply(final WebDriver driver) { return ((JavascriptExecutor) driver).executeScr ...

What is the best way to retrieve the current value of a React useState hook within a setInterval function while using Highcharts

import Error from 'next/error' import React, { useState, useEffect } from 'react' import Highcharts from 'highcharts' import HighchartsReact from 'highcharts-react-official' function generateChart() { const [co ...

Vue JS - Troubleshooting Checkbox Validation Error During Form Submission

When a user fills out my registration form, there is a checkbox to confirm acceptance of the terms and conditions. Currently, the validation error for this checkbox appears immediately upon hitting submit, even though the checkbox starts as unchecked. The ...

Leveraging Vagrant for seamless integration of npm-linked dependencies

Considering a shift in the development process towards Vagrant, I find myself frequently working on interconnected Node modules that have not yet been released, linked together using npm link. However, with Vagrant not sharing all the source files on the ...

Tips on maximizing efficiency in number game coding

Seeking to create a number using a specified set of 6+ inputs. For instance, aiming for the number 280 with inputs [2,4,5,10,30,50,66], the desired output format would be something like this: ((2+5) * 4 * 10). Each input number can only be used once per s ...

Showing an in-depth ngFor post on the screen

I am in the process of building a Blog with Angular 7, MongoDB, and NodeJS. Currently, I have developed a component that iterates through all the posts stored in the database and showcases them on a single page. <div class="container-fluid"> < ...

Unable to adjust the width of the react-select component

I've been struggling to adjust the width of the select element but no matter what I try, it remains at a default width of about 75px. const CustomContainer = styled('div')` width: 100%; height: 100%; display: flex; flex-flow: row wr ...

What is the best way to extract a list of particular items from a nested array?

When I execute the following code: var url="https://en.wikipedia.org/w/api.php?format=json&action=query&prop=categories&titles=Victory_Tests&callback=?"; $.getJSON(url,function(data){ $.each(data, function(i, item) { console.lo ...

Attempting to extract a parameter from a URL and pass it as an argument to a function for the purpose of locating objects based on

I am trying to retrieve data from a URL http://localhost:3000/share/user=sampleuser to display objects with an author value that matches the one in the URL. However, I encountered an error when attempting to call a function that extracts the value from t ...

Troubleshooting jQuery's issue with dynamically adding input fields

I came across a tutorial (which I tweaked slightly) on this website: code In JSFiddle, everything works perfectly fine with the code. However, when I implemented it on my actual page, it's not functioning as expected. I've been trying to trouble ...

What could be causing XMLHttpRequest to encounter issues with the readystate and status states while running on localhost

Hey guys, I'm having some trouble with this code and can't figure out why it's not working. Here is the code snippet: <script> function findMatch() { if(window.XMLHttpRequest) { xmlhttp = new XMLHttpRequest(); ...

The Socket IO system is configured to accept Cross-Origin Resource Sharing (CORS) requests when made through

Currently, I am developing an application that consists of a node backend and an angular frontend. To enable communication between my client and server, I have implemented socket.IO. Initially, I encountered CORS (Cross-Origin Resource Sharing) issues whi ...