Discussion:
receiving HTML response instead of JSON - TDI (SDI)
(too old to reply)
a***@gmail.com
2017-05-30 10:32:43 UTC
Permalink
Raw Message
I'm new to TDI (aka SDI), I am trying to build a REST adapter using the HTTP Client Connector, I tested the request using Postman & Poster and it's working with no problems, however, when I try using SDI I receive the login HTML code instead, here is what should the return: enter image description here

The code I'm using in TDI is the following:

https://i.stack.imgur.com/Nn9eK.png

http = system.getConnector("ibmdi.HTTPClient");
http.initialize(null);
e = system.newEntry();

e["http.url"] = "http://172.31.2.33/aida-web/j_spring_security_check";
e["http.method"] = "POST";
e["http.Content-Type"] = "application/x-www-form-urlencoded";

http.setParam("DECONNECTER_AUTRE_UTILISATEUR", true);
http.setParam("CANAL", "M");
http.setParam("j_username", "AGVISA");
http.setParam("j_password", "admin");

task.logmsg("INFO", "Response" + http.queryReply(e));
Eddie Hartman
2017-05-30 20:39:43 UTC
Permalink
Raw Message
On Tuesday, May 30, 2017 at 12:32:44 PM UTC+2, ***@gmail.com wrote:
> I'm new to TDI (aka SDI), I am trying to build a REST adapter using the HTTP Client Connector, I tested the request using Postman & Poster and it's working with no problems, however, when I try using SDI I receive the login HTML code instead, here is what should the return: enter image description here
>
> The code I'm using in TDI is the following:
>
> https://i.stack.imgur.com/Nn9eK.png
>
> http = system.getConnector("ibmdi.HTTPClient");
> http.initialize(null);
> e = system.newEntry();
>
> e["http.url"] = "http://172.31.2.33/aida-web/j_spring_security_check";
> e["http.method"] = "POST";
> e["http.Content-Type"] = "application/x-www-form-urlencoded";
>
> http.setParam("DECONNECTER_AUTRE_UTILISATEUR", true);
> http.setParam("CANAL", "M");
> http.setParam("j_username", "AGVISA");
> http.setParam("j_password", "admin");
>
> task.logmsg("INFO", "Response" + http.queryReply(e));

Maybe you need to tell the service what you expect:

e["http.Accept"] = "application/json"

What does the html look like that you get back?
a***@gmail.com
2017-05-31 15:31:19 UTC
Permalink
Raw Message
On Tuesday, 30 May 2017 20:39:44 UTC, Eddie Hartman wrote:
> On Tuesday, May 30, 2017 at 12:32:44 PM UTC+2, ***@gmail.com wrote:
> > I'm new to TDI (aka SDI), I am trying to build a REST adapter using the HTTP Client Connector, I tested the request using Postman & Poster and it's working with no problems, however, when I try using SDI I receive the login HTML code instead, here is what should the return: enter image description here
> >
> > The code I'm using in TDI is the following:
> >
> > https://i.stack.imgur.com/Nn9eK.png
> >
> > http = system.getConnector("ibmdi.HTTPClient");
> > http.initialize(null);
> > e = system.newEntry();
> >
> > e["http.url"] = "http://172.31.2.33/aida-web/j_spring_security_check";
> > e["http.method"] = "POST";
> > e["http.Content-Type"] = "application/x-www-form-urlencoded";
> >
> > http.setParam("DECONNECTER_AUTRE_UTILISATEUR", true);
> > http.setParam("CANAL", "M");
> > http.setParam("j_username", "AGVISA");
> > http.setParam("j_password", "admin");
> >
> > task.logmsg("INFO", "Response" + http.queryReply(e));
>
> Maybe you need to tell the service what you expect:
>
> e["http.Accept"] = "application/json"
>
> What does the html look like that you get back?

I did try this but still getting the same result, the HTML i'm getting is the code of the login page, this usually happen when wrong content-type/url or wrong parameters are specified, but all the parameters I specified are correct, here is the result from another tool (poster):
http://imgur.com/a/m8Jqo
yn2000
2017-05-31 18:03:49 UTC
Permalink
Raw Message
Try configure the HTTP Client Connector without the parser.
Hopefully it helps
Rgds, YN.
yn2000
2017-05-31 18:07:29 UTC
Permalink
Raw Message
Oh yes, sorry, you have to construct your own JSON body when you POST.
Rgds. YN
a***@gmail.com
2017-06-02 10:00:57 UTC
Permalink
Raw Message
On Wednesday, 31 May 2017 18:07:31 UTC, yn2000 wrote:
> Oh yes, sorry, you have to construct your own JSON body when you POST.
> Rgds. YN

I even tried the fancy method by configuring the adapter using the UI but still no success...
Loading...