Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
2

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

New Here ,
May 22, 2024 May 22, 2024

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);
});

TOPICS
JavaScript , Modern Acrobat , PDF
312
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
1 ACCEPTED SOLUTION
New Here ,
May 23, 2024 May 23, 2024
LATEST

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.

View solution in original post

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
May 23, 2024 May 23, 2024

May be that assessmentJsonString is empty.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 23, 2024 May 23, 2024
LATEST

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines