RestSharp with Bonita Open Solution - Setting body on RestSharp

49 views
Skip to first unread message

Makrea

unread,
May 25, 2012, 7:51:43 AM5/25/12
to RestSharp
Short story:
I can make a HTTP request to Bonita Open Solution REST API with
success using Advanced Rest Client of Google Chrome and can't do the
same using RestSharp.

Long story (all the code is there):
I posted my issue on the Bonita forum.
http://www.bonitasoft.org/forum/viewtopic.php?pid=39108#p39108

This link, right at the start, states that to define variables one
must set the Body:
http://www.bonitasoft.org/forum/viewtopic.php?id=7580

I tried to use
request.AddParameter("text/xml", body, ParameterType.RequestBody);

or

request.AddBody(body);

but didn't worked.

Maybe something has to be done that I'm unaware.

If any of you can help me it would be great.

Makrea

Makrea

unread,
May 25, 2012, 2:05:52 PM5/25/12
to RestSharp
Well, now it works. :)

Now I'm using this below, (like on bonita post), but after this I do a
UrlEncode, define a Parameter, and do the request.

//trying by constructing a XML similar to form mode of
Advanced Rest Client
body = "variables=<map>";

//24/5/2012 - defining the variables passed by arg
if (nomeVariavel1.Length != 0 && valorVariavel1.Length !=
0)
{
xmlaux = "<entry><string>" + nomeVariavel1 + "</
string><string>" + valorVariavel1 + "</string></entry>";
body = body + xmlaux;
}

//24/5/2012 - defining the variables passed by arg
if (nomeVariavel2.Length != 0 && valorVariavel2.Length !=
0)
{
xmlaux = "<entry><string>" + nomeVariavel2 + "</
string><string>" + valorVariavel2 + "</string></entry>";
body = body + xmlaux;
}

body = body + "</map>";

aux = HttpUtility.UrlEncode(body);//added: using
System.Web;

request.AddParameter("variables", aux);//IT WORKS!!!!!

//var response = new RestSharp.RestResponse();
IRestResponse response;

try
{
response = client.Execute(request);

.......

After this checking the generated Process Instance in User Experience
has the values are there.

Notes:
Changed the RestSharp dll from 102.7 to 103.1.
Had to change the Target Framework to support System.Web reference.

Maybe this can help someone. :)

Bonita and RestSharp FTW! :D

Makrea


On May 25, 12:51 pm, Makrea <agut...@gmail.com> wrote:
> Short story:
> I can make a HTTP request to Bonita Open Solution REST API with
> success using Advanced Rest Client of Google Chrome and can't do the
> same using RestSharp.
>
> Long story (all the code is there):
> I posted my issue on the Bonita forum.http://www.bonitasoft.org/forum/viewtopic.php?pid=39108#p39108
Reply all
Reply to author
Forward
0 new messages