How i can turn off automatic redirect of HTTP client?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-07-2017 02:44 AM
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.
- Labels:
-
Integrations
-
Scripting and Coding
- 3,784 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2017 04:28 AM
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()?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2018 07:09 AM
Do you happen to have an example code of how you did this work around? I am having the same issue.
Thanks.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2020 09:26 PM
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..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-05-2020 03:51 PM
Hi
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?