- Posts: 5
 
URL validation
- Daniel
 - Topic Author
 - Offline
 - User
 - 
            
         
        Less
        More
        
            
    
        
            
        
                6 years 4 months ago                #3509
        by Daniel
    
    
            
            
            
            
            
                                
    
                                                
    
        URL validation was created by Daniel            
    
        Hello, 
Just wondering if there is a quick and easy way to validate urls as part of my flowheater process of transforming a CSV file into XML.
I have a list of 100K urls for product links that need to validate, by showing a 200 or 404 status code. Thank you for the help!
    Just wondering if there is a quick and easy way to validate urls as part of my flowheater process of transforming a CSV file into XML.
I have a list of 100K urls for product links that need to validate, by showing a 200 or 404 status code. Thank you for the help!
Please Log in or Create an account to join the conversation.
- FlowHeater-Team
 - 
            
				
                                 - Offline
 - Admin
 - 
            
         
        Less
        More
        
            
    
        - Posts: 449
 
            
        
                6 years 4 months ago                #3510
        by FlowHeater-Team
    
    
            
Best wishes
Robert Stark
    
 	
					
                                	
			
				    
            
            
            
            
            
                                
    
                                                
    
        Replied by FlowHeater-Team on topic URL validation            
    
        Hi Daniel,
There are two possible solutions maybe.
C# Script to validate a URL)
PowerShell script to validate a URL)
    
            There are two possible solutions maybe.
- Using the 
    .NET Script Heater
 and the short below listed C# script. Very fast and recommended. In this case you have to move one 
    .NET Script Heater
 on the Designer and copy the script below into. Now switch to the “Advanced tab” and add the following line, like the screenshot below.
using System.Net;
At least you have to connect the field containing the URLs to this Heater, the output contains the HTTP status code.
 - Using the 
    CMD Heater
 and a simple PowerShell script (geturl.ps1). In this case you have to move one 
    CMD Heater
 on the Designer. To execute PowerShell scripts you have to use “powershell.exe” for the execute parameter. For the “Parameter” part you have to use the following line like the screenshot below.
-ExecutionPolicy bypass -File geturl.ps1 "$1"
Note: $1 will be dynamically replaced with the value off the first input parameter! The Heater output contains the HTTP status code. 
C# Script to validate a URL)
Code:
public object DoWork()
{
  int statuscode = 404;
  
  // get first input parameter = url to validate
  string url = (string)InValues[0].GetString();    
  var request = HttpWebRequest.Create(url);
  request.Method = "HEAD";
  
  try
  {
    using (var response = request.GetResponse() as HttpWebResponse)
    {
      if (response != null)
      {
        statuscode = Convert.ToInt32(response.StatusCode);
        response.Close();
      }
    }
  }
  catch(WebException ex)
  {
    var response = ex.Response as HttpWebResponse;
    statuscode = Convert.ToInt32(response.StatusCode);
  }
  return statuscode;
}
PowerShell script to validate a URL)
Code:
param([string]$url)
Write-Host -NoNewline "Check URL $url ... "
$request = [system.Net.WebRequest]::Create($url)
try
{
    $response = $request.GetResponse()
} 
catch [System.Net.WebException]
{
    $response = $_.Exception.Response
}
Write-Host "done"
# return current http status code
exit [int]$response.StatusCode
Best wishes
Robert Stark
Attachments:
            	      
												
            	
            	Please Log in or Create an account to join the conversation.
        Time to create page: 0.276 seconds