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

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

New Here ,
May 22, 2024 May 22, 2024

Copy link to clipboard

Copied

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

Views

238
Translate

Report

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

Copy link to clipboard

Copied

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

Votes

Translate

Report

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

Copy link to clipboard

Copied

May be that assessmentJsonString is empty.

Votes

Translate

Report

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

Copy link to clipboard

Copied

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.

Votes

Translate

Report

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