#1 2016-09-02 08:37:49

reg4app
Member
Registered: 2016-05-16
Posts: 147

How to send raw JSON data with the HttpClient control

for SimplePost ,the online doc is about:

SimplePost "Request URL" "Result variable"

Argument name 	Argument type 	Argument value
Request URL 	String 	URL to use in the performing HTTP request
Post data 	String 	Key/value pairs of data to send in the HTTP request.
Result variable 	String 	Variable name in which store the HTTP response

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

Thanks!;)


Joshua.Y

Offline

#2 2016-09-02 12:09:43

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

Hello Joshua,

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

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:

sVpoo7E.png

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.

uzzk1rD.png

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!

Offline

#3 2016-09-05 06:56:40

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

SimplePost "http://url:4242/hello" "A1:AAAAAAA|B1:BBBBBBBB" "[Textarea1.Value]"

and I get this in Request.Content:

-----------------------------10342229454176
Content-Disposition: form-data; name="A1"

AAAAAAA
-----------------------------10342229454176
Content-Disposition: form-data; name="B1"

BBBBBBBB
-----------------------------10342229454176--

...,can I post json data??

Last edited by reg4app (2016-09-05 07:11:18)


Joshua.Y

Offline

#4 2016-09-05 17:20:59

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

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...

Offline

#5 2016-09-06 05:20:48

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

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


Joshua.Y

Offline

#6 2016-09-06 08:43:54

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

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


Joshua.Y

Offline

#7 2016-09-06 10:24:55

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

Hello Joshua,

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

Offline

#8 2016-09-06 10:42:55

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

I just follow the server sample smile

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


Joshua.Y

Offline

#9 2016-09-06 10:46:38

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

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?

Offline

#10 2016-09-06 10:52:05

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

Hello again,

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

Offline

#11 2016-09-06 13:03:20

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

Hello Joshua,

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

Offline

#12 2016-09-06 17:50:33

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

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.

Offline

#13 2016-09-07 02:58:48

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

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


Joshua.Y

Offline

#14 2016-09-07 04:03:05

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

Confirm

work like a charm!!
smile
Thanks again!


Joshua.Y

Offline

#15 2016-09-07 08:22:41

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

Hello Joshua,

Always thanks for your support sir! wink

Offline

#16 2016-11-11 00:06:13

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

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!

Offline

#17 2016-11-16 02:48:06

reg4app
Member
Registered: 2016-05-16
Posts: 147

Re: How to send raw JSON data with the HttpClient control

a third way!?Html form
sound nice!

big_smile and big_smile


Joshua.Y

Offline

#18 2016-11-16 08:49:48

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,657
Website

Re: How to send raw JSON data with the HttpClient control

reg4app wrote:

a third way!?Html form
sound nice!

big_smile and big_smile

Thanks Joshua!

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.