Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace WebTestsAndDemos
- {
- using System;
- using System.Net;
- using System.Text;
- class Program
- {
- static void Main()
- {
- //task 1
- var inputUriTest = Console.ReadLine();
- var inputUriDecoded = WebUtility.UrlDecode(inputUriTest);
- Console.WriteLine(inputUriDecoded);
- //task 2
- try
- {
- var inputUri = Console.ReadLine();
- var uriTest = new Uri(inputUri);
- var result = new StringBuilder();
- if (!uriTest.IsWellFormedOriginalString())
- {
- result.AppendLine("Invalid URL");
- }
- var validHttp = uriTest.Port == 80 && uriTest.Scheme == "http";
- var validHttps = uriTest.Port == 443 && uriTest.Scheme == "https";
- if (validHttps || validHttp)
- {
- result.AppendLine($"Protocol: {uriTest.Scheme}");
- result.AppendLine($"Host: {uriTest.DnsSafeHost}");
- result.AppendLine($"Port: {uriTest.Port}");
- var path = WebUtility.UrlDecode(uriTest.LocalPath);
- result.AppendLine($"Path: {path}");
- var query = WebUtility.UrlDecode(uriTest.Query);
- if (uriTest.Query != string.Empty)
- {
- result.AppendLine($"Query: {query.TrimStart('?')}");
- }
- var fragment = WebUtility.UrlDecode(uriTest.Fragment);
- if (uriTest.Fragment != string.Empty)
- {
- result.AppendLine($"Fragment: {fragment.TrimStart('#')}");
- }
- }
- else
- {
- result.AppendLine("Invalid URL");
- }
- Console.WriteLine(result.ToString().Trim());
- }
- catch (Exception e)
- {
- Console.WriteLine("Invalid URL");
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement