Http request 301 document has moved

Hallo.

I have an issue about my POST HTTP request.

After i have given my Bearer token, ill get this issue:

“message”: “\n\n301 Moved Permanently\n\n

Moved Permanently

\n

The document has moved <a href="http:****">here.

\n
\nApache/
(Ubuntu) Server at ****** Port **\n\n”,

It looks like im getting redirected and therefor getting this message.

When im doing the exact same thing through POSTMAN, it works fine.
In POSTMAN this setting is turned on. When i turn it OFF ill get the same issue as in UiPath.

Can someone please help? :slight_smile:

@christian.bendtsen

Automatic redirects is not yet a available feature in http request activity. As if now it is a limitation

You can try using custom code for the http request and use AllowAutoredirectProperty

Cheers

Some statements from above maybe needs to be crosschecked (as HTTP Request did in the lab the following automatically). But for checking redirections also have a look here:

Hey
I’ll tried to invoke the code, and used AllowAutoredirected, but nothing changes…

the websites are the same, only changes is the ‘s’ in the http, i’ll try to change that as well, still got the same problem :frowning:

this part is unclear on what was done in detail, what was returned

Returned: “http://"
insted of:"https://

I have already disabled “Enable SSL certificate verification”

Do you have any other good suggestions? :slight_smile:

@christian.bendtsen

When you say you tried invoke code…Can you show the code you tried…

cheers

try
        {
			var webRequest = System.Net.HttpWebRequest.Create(strEndPoint) as System.Net.HttpWebRequest;
            if (webRequest != null)
            {
                webRequest.Method = "POST";
                webRequest.Timeout = 60000;
                webRequest.ContentType = "application/json;v=1";
				webRequest.Accept="application/json;v=1";
				webRequest.Headers.Add("Accept-Encoding","gzip, deflate, br");
				webRequest.AllowAutoRedirect=true;
                webRequest.Headers.Add("Authorization", StrToken);
				using (var streamWriter = new StreamWriter(webRequest.GetRequestStream()))	{		
				}
							
				using (System.IO.Stream s = webRequest.GetResponse().GetResponseStream())
                {
                    using (System.IO.StreamReader sr = new System.IO.StreamReader(s))
                    {
                        StrResponse = sr.ReadToEnd();
                    }
					
                }
				IntStatusCode = 200;
            }
        }
        catch (System.Net.WebException ex)
        {
			if (ex.Status == System.Net.WebExceptionStatus.ProtocolError)
            {
				
                var response = new StreamReader(ex.Response.GetResponseStream()).ReadToEnd();
                Console.WriteLine("Errorcode: {0}", response);
				StrResponse = response.ToString();
				IntStatusCode = (int) ((System.Net.HttpWebResponse) ex.Response).StatusCode;
				
            }
            else
            {
                Console.WriteLine("Error: {0}", ex.Status);
            }
        }Preformatted text

here you go, its written in C#

@christian.bendtsen

Try including a cookie container as well

CookieContainer cookieContainer = new CookieContainer();
WebRequest.CookieContainer = cookieContainer;

And I hope in Postman when autoredirect is set to true that is when you have the correct request output

cheers

@christian.bendtsen
Kindly note why we mentioned HttpClient (attached link from above to the redirect detection code lines) for new Custom Implementations:


Taken from:

2 Likes