The CreatorCon Call for Content is officially open! Get started here.

How i can turn off automatic redirect of HTTP client?

maximus
Tera Expert

Hi All.

We faced with unexpected behavior and want to ask for advice.

We need to import data from the site. To get that information we should call PHP script, but we should be authorized first. Authorization performed by another PHP script, which generates the cookie and redirects to main page of the site.

When we try to send REST request by ARC - it returns empty body and 9 headers (include Set-Cookie and Location). From that response we can take cookie and can make call for data.

We try to make call from ServiceNow. Fist we use RESTMessageV2 object. We provided the same header and parameters of POST request. But in the response object we receive result with performed redirect   to main page of the site. And there is no cookies in the response.

Then we try to use   GlideHTTPClient - result was the same. Body of the response contained data of main page, no cookies in header. Also we try to set setInstanceFollowRedirects to false, but there is no success.

So we wonder if there any way to stop automatic redirecting of HTTP client? Or may be HTTP client storing Cookies somewhere and there is a chance to get them?

Many thanks in advance.

6 REPLIES 6

maximus
Tera Expert

Currently we found a workaround.


Object   Packages.org.apache.commons.httpclient.HttpClient() performs correct call without any redirection.


only disadvantage is that we can make call only from global application.



Any idea how it is possible to force GlideHttpClient, GlideHttpRequest and RestMEssageV2 work with rediretion as Packages.org.apache.commons.httpclient.HttpClient()?


Do you happen to have an example code of how you did this work around? I am having the same issue.



Thanks.


Hi.. please see the comment below about sys_property.

If it does not work for you, please, let me know -  we will try to help.

 

You can find me in skype by name m.chernyavsky..

lcc
Tera Expert

Hi @maximus , understand that this was an old post but I'm currently facing the same issue. I tried to use the HTTPClient method as you mentioned above by referring to John Andersen's blog.

http://www.john-james-andersen.com/blog/service-now/service-now-is-not-afraid-to-get-rest.html

When I added get.setFollowRedirects(false); to the source code, i got the following error:

java.lang.SecurityException: Illegal access to method setFollowRedirects(boolean) in class org.apache.commons.httpclient.HttpMethodBase

I wrote the script in GLOBAL application. I wonder if you had facing the same issue before and how did you get around it?