ridicurious.com
Powershell, Productivity

Query HTTP Status Code detailed information using Powershell

Introduction:

While socket programming with Python, I realized that I was getting some strange HTTP Status codes, but I had no idea what they actually meant.

I googled it and found instant results from a couple of cool websites, but I was wondering if can web harvest HTTP Status code information from a website and wrap it in a function which can query these statuses to add more verbosity to my web requests.

On top of that, once I have the HTTP Status codes and their description in a CSV, JSON or XML format,  I can repurpose this data in any program/script as desired which is obviously way better than Googling it each and every time when troubleshooting such errors.

 

Making it work:

    1. First get information for all the HTTP status code, but where to get it? I figured out many websites that have such information like https://httpstatuses.com/ and if you inspect the source code of the website you can easily web harvest this data1Similarly, more detailed description of these HTTP status codes can be accessed by suffixing the URL with the status code like in the following image

      So I wrote a small PowerShell script (below) to web request and capture this information from the website and export the result to CSV file.

      Once you have the information in CSV format you require this file to be accessible so that it can be easily downloaded over the internet from anywhere in the world.In order to achieve this, I copy-pasted/committed it to my Github repository from where it could be downloaded to any machine with access to the internet since the file is Public.

    2. Write a Powershell function that can
      • Web request above mentioned public Github gist URL and downloads the contents of the CSV file.
      • Filter out the HTTP status code you’re trying to search from the content and display its description

    3. When the Powershell function runs for the first time, it creates a local copy of content in a File at a static location, which could be accessed to get HTTP status codes information locally for all Future function calls by avoiding the Web request which is slower.Took care of point-4 in my PowerShell function like in the screenshot below

Script:

Running the Function:

You can run the function on demand like in the below screenshot.

NOTE – The first call to the function would be slow, but from the next call you have a local copy of the CSV file on your machine, which can be queried comparatively much faster to web requests.

If you liked it, do check out PSDecode Module which is PowerShell based module that can decode System Errors, Exit codes, port numbers, HTTP Return codes and MAC Vendors. This module can be used to quick lookup Error descriptions.

Hope you’ll find the script useful, please don’t forget to share this script with your friends and colleagues.

Thanks for reading! 🙂

Related posts

Get MAC Vendor using PowerShell

Prateek Singh
7 years ago

Modify Powershell XML Indentation for Readability

Prateek Singh
7 years ago

Programmatically Scroll Internet Explorer with PowerShell

Prateek Singh
7 years ago
Exit mobile version