Skip to main content
Participant
May 23, 2024
Answered

Adding Content-Type to a Net.HTTP.request()

  • May 23, 2024
  • 1 reply
  • 388 views

I have a simple function that sends some JSON to my API.

 

However, when the server receives it, it says the the Content Type is invalid as it is '' (empty).

 

var saveAssessment = app.trustedFunction(function() {
    const params = {

       cVerb: "POST",
       cURL: "http://localhost:8089/api/step-by-step-assessment",
       oBody: assessmentJsonString,
       aHeaders: {
          "Content-Type": "application/json",

       },
       oHandler: {
          response: function(msg, uri, error) {
             if (error != undefined) {
                app.alert("Error ocurred: " + JSON.stringify(error));
             } else app.alert("Success!");
          },

       }

    };

 

    Net.HTTP.request(params);
});

This topic has been closed for replies.
Correct answer AlecSouth

The assessmentJsonString is not null, I just excluded it from the post.

 

I did actually find the solution, which was changing my endpoint to accept 'application/octet-stream'. Because, changing the Content-Type did not actually change it's type.

1 reply

Bernd Alheit
Community Expert
Community Expert
May 23, 2024

May be that assessmentJsonString is empty.

AlecSouthAuthorCorrect answer
Participant
May 23, 2024

The assessmentJsonString is not null, I just excluded it from the post.

 

I did actually find the solution, which was changing my endpoint to accept 'application/octet-stream'. Because, changing the Content-Type did not actually change it's type.