HTTP Request needs Proxy Authentication

Hi all, I’m trying to make a request to one of our company APIs using the HTTP request activity. I’m only having issues with one API call as this particular API needs Proxy Authentication, so I’m getting the 407 HTTP response code. I believe the HTTP request activity in UiPath does not have any support for Proxy Authentication within the activity itself.

Can I use the Invoke Code activity to execute a piece of code that would authenticate the proxy credentials? I have the credentials already, and know the URL I need to send the request to, but I’m unsure of how the code would look in the Invoke Code activity. I would much appreciate any help, or any other solutions. Thank you

An update, I’ve managed to used the Incoke Code activity to use VBNet code, to call one of our APIs (a GET request). Below is the code:

Dim fr As System.Net.HttpWebRequest
Dim targetURI As New Uri(strURL)

fr = DirectCast(HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)

Dim webProxy As IWebProxy = New WebProxy(strIpAddressAndPort)
webProxy.Credentials = New NetworkCredential(strProxyUsername, strProxyPassword)
fr.Proxy = webProxy
fr.Credentials = New NetworkCredential(strSimpleAuthUsername, strSimpleAuthPassword)

Dim username As String = strSimpleAuthUsername
Dim password As String = strSimpleAuthPassword
Dim encoded As String = System.Convert.ToBase64String(Encoding.GetEncoding(“ISO-8859-1”).GetBytes(username + “:” + password))
fr.Headers.Add(“Authorization”, "Basic " + encoded)

Dim res As HttpWebResponse = DirectCast(fr.GetResponse(), System.Net.HttpWebResponse)
webRes = res

Dim html As String = New StreamReader(res.GetResponseStream()).ReadToEnd()
strHtml = html


Some notes:

strProxyIpAddressAndPort is in the form: IpAddress:PortNumber e.g. 192.168.1.1:8080
strURL is the API endpoint
strURL, strIPAddressAndPort, strProxyUsername, strProxyPassword, strSimpleAuthUsername, strSimpleAuthPassword are In Arguments
webRes and strHtml are Out Arguments


I tried to use similar code (but adding additional headers and code) in another API call for a PUT request, but that’s giving me the 403 error (Forbidden). We ended up not having to use this Environment for our application since it’s only in this environment where proxy authentication is needed.

Hopefully this helps someone that is having a similar issue. Cheers!

Thanks for this code. It helps us. We have to send post request and facing issues with the code how to pass body content in this code.

Can you please help here.

Dim fr As System.Net.HttpWebRequest
Dim targetURI As New Uri(strURL)
Dim byteData As Byte()
Dim postStream As Stream = Nothing

fr = DirectCast(HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)
Dim webProxy As IWebProxy = New WebProxy(strIpAddressAndPort)
webProxy.Credentials = New NetworkCredential(strProxyUsername, strProxyPassword)
fr.Proxy = webProxy

fr.Headers.Add(“Authorization”, jwtOutput)
fr.Headers.Add(“zapiAccessKey”, “nnn”)

fr.Method= “POST”

byteData = System.Text.Encoding.UTF8.GetBytes(NewContent.ToString())

fr.ContentType = “application/json”
fr.ContentLength = byteData.Length

postStream = fr.GetRequestStream()
postStream.Write(byteData, 0, byteData.Length)

Dim res As HttpWebResponse = DirectCast(fr.GetResponse(), System.Net.HttpWebResponse)
webRes = res

Dim html As String = New StreamReader(res.GetResponseStream()).ReadToEnd()
strHtml = html

Tried above code but proxy authentication issue is throwing.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.