The MobileFirst Platform adapter is refusing to accept the JSON array in the body of my request

Currently utilizing MobileFirst Platform 6.3, my aim is to send the request below:

var input = {
    method : 'post',
    path : "/create/item.aspx",
    body: {
        contentType:'application/json; charset=UTF-8',
        content: JSON.stringify([{"item": "name"}])
    }
};

var outputObj = WL.Server.invokeHttp(input);

In an effort to simplify the issue, I have minimized the request as much as possible. Strangely, it seems that having a string containing an array in the body.content section is causing some unknown behavior, resulting in the body not being transmitted to the backend.

Unfortunately, modifying the backend is not an option for me, so alternative solutions such as wrapping the array or changing the input structure are out of the question.

If anyone could shed some light on why this might be happening with my body content and offer advice on how to prevent WorkLight from altering it, I would greatly appreciate it.

Answer №1

I decided to experiment with a nodejs server just to observe the data being received from the adapter, and everything seems to be working smoothly.

Below is my snippet of adapter code:

    var input = {
    method : 'post',
    returnedContentType : 'plain',
    path : "/mypath",
    body:{
        contentType:"application/json; charset=UTF-8",
        content: JSON.stringify([{"item": "name"}])
    }
};


return WL.Server.invokeHttp(input);

The output generated by the server looks like this:

Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     URL :: /
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Method :: POST
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Header :: content-length=17
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Header :: content-type=application/json; charset=UTF-8
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Header :: host=localhost:1111
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Header :: connection=Keep-Alive
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Header :: user-agent=Apache-HttpClient/4.3.4 (java 1.5)
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Cookies >> undefined
Thu Dec 11 2014 11:18:47 GMT-0600 (CST)     Body :: [{"item":"name"}]

If you're facing issues, it's possible that the problem lies on the backend side. I recommend checking what response you receive from the backend. Make sure to include the property returnedContentType : 'plain' in your invocation options to properly analyze the output of WL.Server.invokeHttp().

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

Incorrect scroll position being updated

My current project involves dynamically adding a class to the DOM based on scroll position. If the scroll position is 150 or above, a class is added, and if it's less than 150, the class is removed. Everything works fine when scrolling down, but when ...

What is the best way to effectively apply chunking and batching when working with a group of promises or async functions?

When processing a large collection of async functions in batches, I am presented with two different scenarios: Scenario 1: Gathering all the async functions import { chunk } from "lodash"; const func = async () => new Promise((resolve) =& ...

Using JavaScript to effectively handle my JSON data

I've been trying to retrieve the data from my JSON file, but I keep getting an error in the console that says "Uncaught TypeError: Cannot read property 'longitude' of undefined." This method is new to me and I would really appreciate any hel ...

Is there a more efficient method to achieve the desired effect without making multiple calls to jQuery ajaxSuccess?

Currently, I am working on creating an effect that involves a quick fade-out followed by a fade-in of the element once the request is successful. Since jQuery processes elements in a routine manner (top to bottom), I have managed to achieve my desired eff ...

Creating a Three.js 3D Text Effect with Layers of Letters

Why are my 3D text letters overlapping in the threejs TextGeometry when viewed from an angle? https://i.sstatic.net/W0ocu.png See the code snippet below: class MyScene { // Code for handling Three.js scene and elements constructor(elementSelector ...

embedding a button alongside the pager in an HTML document

I am encountering an issue with the positioning of a button in my paginated table setup. The button is currently displaying below the pager instead of being aligned on the left side of the page along with the pager. https://i.stack.imgur.com/gUiB9.png To ...

The server has detected that the length of the string exceeds the value specified in the maxJsonLength property

Let me start by acknowledging my understanding of the error at hand. I am well aware of <jsonSerialization maxJsonLength="50000000"/> and the valid reasons for implementing a limit. My current situation involves calling a webservice from Jav ...

jqGrid is failing to display basic JSON data properly

As a newcomer to Jquery and Json, I am struggling with binding a JSON object from a RESTful Webservice written in WCF to jqGrid. Despite saving the JSON object as a static file and attempting to bind it to the grid, I realized that the issue does not lie w ...

Angularjs pledged to utilize $http for its functionality

$http({ url: '/verifyUserName', data:{username:$scope.username}, method: "POST" }) .then(function(response) { $scope.allowGameStart = true; }) Is there a way to access the variable $scope.allowGameStart outside of the promise in ...

Having trouble with uploading images on Angular 6 platform

Utilizing 'ngx-image-cropper' for image cropping and sending the base64 value of the image to a server has been causing occasional null value issues. Despite implementing 'DOMSanitizer' in Angular to upload and securely mark images, the ...

Switch button displaying stored data in sessionStorage

I am facing an issue with my small toggle button in AngularJS. I have set up sessionStorage to store a value (true or false), and upon page load, I retrieve this value from sessionStorage to display the toggle button accordingly. Depending on the value sto ...

Obtain the IP address of a Node application running within a Docker container

I currently have a node express application set up in a Docker container, and I am attempting to record the IP address of each incoming request within the app. However, due to running behind a firewall, my current method "req.headers['x-forwarded-for& ...

What is the reason for receiving the message "none is installed You must install peer dependencies yourself" after running "npm install"?

I'm having trouble setting up a react/redux/ionic app. After running npm install, I encountered some errors: >`enter code here`npm install npm WARN @ionic/<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a7d5c2c6c4d3e79 ...

Invoke the controller function to retrieve information on the client side

I need to make a call to a server-side controller method that will return a string, eventually formatted as JSON. Once I receive this data on the client side, I want to use it to update a specific part of the user interface. Here is my current setup: Con ...

Error: obj is not a valid operand for the 'in' function when attempting to retrieve data with JQuery JSON

Check out this code snippet jQuery('select[name="' + element + '"]').html('<option value="">Select</option>'); jQuery.each(data, function(key, value) { jQuery('selec ...

Utilizing JavaScript to interact with MATLAB as a COM Automation Server

Struggling to create a link between Matlab and a Javascript (specifically typescript) program using a COM automation server, as recommended on the MathWorks website. While the documentation provides examples for certain languages supported by Microsoft, th ...

Why is it that the compare function in bcrypt keeps returning false, even when I am entering the correct password?

I am utilizing Postman to test the login API. The registration API is functioning correctly and securely hashes the password before storing it in the database. However, when attempting to log in using the same credentials, an error message is displayed sta ...

What is the best way to implement JQuery Ajax in order to invoke a PHP file on the server side, which will then execute returned javascripts?

I am currently working on a client website that requires a cross-domain JQuery Ajax call to a PHP file on my server. The purpose of this call is to query the database for various stored JavaScripts, which will then be returned to the client and executed on ...

When you input text into a contenteditable div, it automatically gets placed inside a span element instead of being placed

I'm having an issue with my contenteditable div. Whenever I click the button, a span is inserted into the div. However, when I start typing, the text goes inside the span instead of outside it: jQuery(document).ready(function($) { let input = $(" ...

Using Bootstrap to handle opening a link when a dropdown menu button is clicked

Utilizing Bootstrap in my main menu was essential for navigating through the numerous pages, subpages, and sub-subpages within my project. The dropdownmenu feature proved to be very helpful in this regard. However, my client now has a specific request - t ...