Drop hier links of afbeeldingen om ze aan de editor toe te voegen.

What do the browser error codes mean?

★☆☆

Status codes are issued by a server in response to a client's request made to the server. Typically when your browser requests a web page the host server will give the browser an informational response, a success report, a redirection request or an error.

HTTP error codes

Make

Write a program that outputs what each of these HTTP status codes mean: 400, 401/403, 404. Any other code is an unknown error for the purpose of this program.

Success Criteria

Remember to add a comment before a subprogram or selection statement to explain its purpose.

Complete the subprogram called HttpStatus so that it:

  1. Returns “Bad request” if the status is 400.
  2. Returns “Authentication error” if the status is 401 or 403.
  3. Returns “Not found” if the status code is 404.
  4. Returns “Unknown error” for any other status code.

Typical inputs and outputs from the program would be:

Enter the status code:
404
Not found
🆘 If you're really stuck, use this Parsons code sorting exercise
Complete program
// HTTP status codes program

using System;

class Submission
{
---
    // -------------------------
    // Subprograms
    // -------------------------
    // Return the name of the HTTP error
---
    static string HttpStatus(int status)
    {
---
        switch (status)
        {
---
            // 400 error
            case 400:
                return "Bad request";
---
            // 401 and 403 errors
            case 401:
            case 403:
                return "Authentication error";
---
            // 404 error
            case 404:
                return "Not found";
---
            // All other errors
            default:
                return "Unknown error";
---
        }
---
    }
---

    // -------------------------
    // Main program
    // -------------------------
    public static void Main(string[] args)
    {
---
        Console.WriteLine("Enter the status code:");
        int code = Convert.ToInt32(Console.ReadLine());
        Console.WriteLine(HttpStatus(code));
---
    }
---
}