How to send raw JSON data with the HttpClient control


Yang Ghua

for SimplePost ,the online doc is about:

SimplePost "Request URL" "Result variable"

need more Specific description for This 'Post data'
and the usage for Control HttpClient in post Method

Thanks!;)


DecSoft

Hello Joshua,

Ok. I will take a look at this, but please, Joshua, if you have any specific question, post it here! :)

Basically we can use the "SimplePost" action to perfom an HTTP POST call from our application including one or more key/values. The SimplePost's action editor we can see in the below image, allows us to place one or more key/value pairs in our HTTP POST call in an easy way:

In the above case the server receive two keys: "MyKey1" and "MyKey2", with their two specified values: "MyValue1" and "MyValue2". The server response are saved into the "[MyResultVariable]", but, as you know, there is not available just after the "SimplePost" action is executed, because they are executed in an asynchronous way.

And what happend if we wanted to know the server response of an HTTP POST call after perform it? If this is what we wanted the "HttpClient" control appear to the rescue. This control allow us to perform HTTP calls, also POST calls, and they have two events "Success" and "Error". Once the HTTP call is made, one of such events are fired, then we not only can know the server response, but also if a possible error occur.

How we can set the "key/value" pairs if we use the "HttpClient" control? Using the "HttpSetData" action we can do that. The below image show to us the HttpSetData's action editor. As you can see, we simply must specify the HttpClient control we want to use and the key/value pair we want to establish.

Once our HTTP call is prepared, we just call to the "HttpExecute" action to perform it. One interesting thing to note is that in both cases (by use the "SimplePost" action or an "HttpClient") our key's values can contains variables, and, if this variable is an Input File value, the user choose file is uploaded to the server along the HTTP call. We can take a look at various App Builder samples which deal with this like the "SimplePost", "SimpleFile" and the "HttpClient" samples.

Hope this information can help! Please post here if you have any further question Joshua!



Yang Ghua

and I get this in Request.Content:


...,can I post json data??


DecSoft

Hello Joshua,

Certainly App Builder do not uses a form to perform HTTP POST calls, just certain Javascript "FormData" variable, which is filled in the right way to contain our desired data. You have some problem when receive the POST data in your app's server or something like that?

On the other hand, I will take a look, but, maybe a posible way to send JSON data is to "serialize" an Object variable or just send the JSON inside one of the HTTP POST call variables. Maybe we can also try by changing the HTTP POST call headers, but I am not sure about...



Yang Ghua

it looks like my server expect json data,
I am trying to change the 'form-data' into json..... in server side
not work yet :(


Yang Ghua

use Postman in Chrome to test the Post function ,still get error,
I guess this is about the server ,not AB


DecSoft

Hello Joshua,

Since you talk about "your server", why you expect JSON? That is, you can't deal with other kind of input data?



Yang Ghua

I just follow the server sample :)

and I check the server,it may need a application/json request body,How can I do in AB??


DecSoft

Hello Joshua,

I am not sure if (for the moment) point you to the HTTP documentation of AngularJS, that is, may you can do what you wanted using "pure" Javascript code. On the other hand, I am not sure if another way can be to "transform" the received data in JSON, that is, the server receive the input as the app send it, but, before to proceed, they may can transform that input data into JSON, and then continue the work... what do you think about?



DecSoft

Hello again,

Anyway, I want to study this question in a more deep way as quickly as possible Joshua!



DecSoft

Hello Joshua,

Please, standby,... I am working on a solution for this question.



DecSoft

Hello Joshua,

Please, update your AB copy, new changes and enhancements has been introduced:


2016.181 (09/07/2016)

* Added the new "HttpJson" application sample, which shown us how we can use the new added "Transform" variable of an HttpClient control. Take a look at this sample to view how we can send JSON data in HTTP calls.

* Added a new "Transform" variable to the HttpClient control. This variable can be "data" or "json" and allow us to perform "normal" HTTP POST calls (like always in App Builder) and also JSON HTTP POST calls, that means the call's data is sended as JSON.

* The SetHttpData action do not work as expected for certain specific data key names (which contains invalid characters for Javascript identifiers). This has been fixed now and the action is also enhanced to allow app's variables to be used as key's names.

* The SetHttpHeader action do not work as expected for certain specific header names (which contains invalid characters for Javascript identifiers). This has been fixed now and the action is also enhanced to allow app's variables to be used as header's names.

Let me know if you have any further question or problem Joshua.



Yang Ghua

That is a really good news...,I will try it,Thanks for your quick response


Yang Ghua

Confirm

work like a charm!!
:)
Thanks again!


DecSoft

Hello Joshua,

Always thanks for your support sir! ;)



DecSoft

Hello there!

Another news about this topic is that the new App Builder release incorporates in their HttpClient control a new transformation "form" in addition to "json" and "data". You can take a look at the also new "HttpForm" application sample to look at that. Basically we can send data to a server like if use an HTML form, again, in addition to send "json" and (by default) just "data" (using the FormData Javascript object).

Hope this information can be useful here!



Yang Ghua

a third way!?Html form
sound nice!

:D and =D


DecSoft
a third way!?Html form
sound nice!

:D and =D

Thanks Joshua!


Everybody can read the DecSoft support forum for learning purposes, however only DecSoft customers can post new threads. Purchase one or more licenses of some DecSoft products in order to give this and other benefits.

This website uses some useful cookies to store your preferences.

I agree. Hide this note. Give me more information.