Using invoke powershell activity Need to get the status code if URL works and if URL failed means need to get the failed description
@dany_khanth
depending on the Powershell version (wget alias removed on PowerShell (Core) 7.0.0) you can try following script:
try
{
$status = wget www.google.com | % {$.StatusCode.ToString()}
}
catch [exception]
{
$status = $.Exception.Message.ToString()
}
cls
$status
Throuwing error at line three
At line:3 char:58
- $status = wget www.google.com | % {$.StatusCode.ToString()}
-
~
An expression was expected after ‘(’.
At line:7 char:40
- $status = $.Exception.Message.ToString()
-
~
An expression was expected after ‘(’.
+ CategoryInfo : ParserError: ( , ParentContainsErrorRecordException
+ FullyQualifiedErrorId : ExpectedExpression
but let me check some things in additional
@dany_khanth
Have a look on the different options and its behaviour:
Powershell:
Visuals
Script:
try
{
$status = wget $url | % {$_.StatusCode.ToString()}
}
catch [exception]
{
$status = $_.Exception.Message.ToString()
}
Flow:
Details:
HTTP Activity:
HttpWebRequest API / UiPath
Visuals
myHttpRequest2 = CType(WebRequest.Create(strURL), HttpWebRequest)
myResponse = CType(myHTTPRequest2.GetResponse, HttpWebResponse )
String.Format("Status Form Code HTTPRequest: StatusCode: {0} - Description {1}", CInt(myResponse.StatusCode).toString,myResponse.StatusDescription)
Variables:
When running different cases we get following:
URL OK
URL not existing
Invalid Url
Fazit:
- we can do it with Powershell, but also can do it within UIPath
- HTTP Request Activity is limited for second case and has Status 0
- HTTP Request Coding (Option 3) is close to the Powershell
Find starter Help here:
CheckURL.xaml (12.4 KB)
CheckURL.ps1.txt (139 Bytes)
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.