Hello World


When you press the button some text will appear in the text box.
Create a NotePad file called "testing.aspx"

<%@ Page Language="C#" %> 
<%@ Import Namespace="System.Web.UI" %>

<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
   TextBox1.Text = "Hello world";
   TextBox1.Text = DateTime.Now.ToShortTimeString();
}
</script>

<html>
<body>
   <h1>Hello World</h1>
   <br/>
   <form runat="server">
   <asp:TextBox id="TextBox1" runat="server" />
   <br/>
   <asp:Button id="Button1" onClick="Button1_Click" Text="Button1" runat="server" />
   </form>
</body>
</html>

HMRC - 1

<%@ Page Language="C#" %> 

<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
    string content = null;
 
    System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://test-api.service.hmrc.gov.uk/hello/world");

    request.Accept="application/vnd.hmrc.1.0+json";

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream stream = response.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    {
        content = sr.ReadToEnd();
    }
 
    TextBox1.Text = content;
}
</script>

<html>
<body>
   <h1>HMRC Testing</h1>
   <br/>
   <form runat="server">
   <asp:TextBox id="TextBox1" runat="server" />
   <br/>
   <asp:Button id="Button1" onClick="Button1_Click" Text="Button1" runat="server" />
   </form>
</body>
</html>

HMRC - 2

<%@ Page Language="C#" %> 

<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
    string content = null;

      var parametersJSON =
         "{\"client_id\":\"" + "ezza0cjMWfY8hybuzuEs1NTsym5j" + "\"," + "\"client_secret\":\"" + @"af73e8bb-90c2-4baa-bd75-f74d5df7e4f3" + "\"," + "\"scope\":\"" + "hello" + "\"," + "\"grant_type\":\"" + "client_credentials" + "\"," + "\"redirect_uri\":\"" + "https://bettersolutions.com/testing.aspx" + "\"" +
         "}";
 
    System.Net.HttpWebRequest request = (System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://test-api.service.hmrc.gov.uk/oauth/token");

    request.Method="POST";

    request.Accept="application/vnd.hmrc.1.0+json";

    request.ContentType = "application/json";

    var streamWriter = new System.IO.StreamWriter(request.GetRequestStream());
    streamWriter.Write(parametersJSON);
    streamWriter.Flush();
    streamWriter.Close();

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

    System.IO.Stream stream = response.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    {
        content = sr.ReadToEnd();
    }
 
    TextBox1.Text = content;
}

void Button2_Click(object sender, EventArgs e)
{
    string content = null;

    System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://test-api.service.hmrc.gov.uk/hello/application");

    request.Accept="application/vnd.hmrc.1.0+json";

    request.Headers.Add("Authorization", "Bearer " + TextBox2.Text);

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream stream = response.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    {
        content = sr.ReadToEnd();
    }
 
    TextBox3.Text = content;
}
</script>

<html>
<body>
   <h1>HMRC Testing</h1>
   <br/>
   <form runat="server">
   <asp:Button id="Button1" onClick="Button1_Click" Text="Get Access Token" runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox1" Width=900 runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox2" Width=900 runat="server" />
   <br/> <br/>
   <asp:Button id="Button2" onClick="Button2_Click" Text="Get Response" runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox3" Width=900 runat="server" />
   </form>
</body>
</html>

HMRC - 3

<%@ Page Language="C#" %> 

<script runat="server">
void Button1_Click(object sender, EventArgs e)
{
    string content = null;
    TextBox1.Text = @"https://test-api.service.hmrc.gov.uk/oauth/authorize?response_type=code&client_id=ezza0cjMWfY8hybuzuEs1NTsym5j&scope=hello&redirect_uri=https://bettersolutions.com/testing.aspx";
}

void Button2_Click(object sender, EventArgs e)
{
    string content = null;

    var parametersJSON =
         "{\"client_id\":\"" + "ezza0cjMWfY8hybuzuEs1NTsym5j" + "\"," + "\"client_secret\":\"" + @"af73e8bb-90c2-4baa-bd75-f74d5df7e4f3" + "\"," + "\"grant_type\":\"" + "authorization_code" + "\"," + "\"code\":\"" + TextBox2.Text+ "\"," + "\"redirect_uri\":\"" + "https://bettersolutions.com/testing.aspx" + "\"" +
         "}";
 
    System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://test-api.service.hmrc.gov.uk/oauth/token");

    request.Method="POST";

    request.Accept="application/vnd.hmrc.1.0+json";

    request.ContentType = "application/json";

    var streamWriter = new System.IO.StreamWriter(request.GetRequestStream());
    streamWriter.Write(parametersJSON);
    streamWriter.Flush();
    streamWriter.Close();

    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Ssl3 | System.Net.SecurityProtocolType.Tls12 | System.Net.SecurityProtocolType.Tls11 | System.Net.SecurityProtocolType.Tls;

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();

    System.IO.Stream stream = response.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    {
        content = sr.ReadToEnd();
    }

    TextBox3.Text = content;
}

void Button3_Click(object sender, EventArgs e)
{
    string content = null;

    System.Net.HttpWebRequest request =
(System.Net.HttpWebRequest)System.Net.WebRequest.Create("https://test-api.service.hmrc.gov.uk/hello/user");

    request.Method="GET";

    request.Accept="application/vnd.hmrc.1.0+json";

    request.Headers.Add("Authorization", "Bearer " + TextBox4.Text);

    System.Net.HttpWebResponse response = (System.Net.HttpWebResponse)request.GetResponse();
    System.IO.Stream stream = response.GetResponseStream();
    System.IO.StreamReader sr = new System.IO.StreamReader(stream);
    {
        content = sr.ReadToEnd();
    }
 
    TextBox5.Text = content;
}
</script>

<html>
<body>
   <h1>HMRC Testing</h1>
   <br/>
   <form runat="server">
   <asp:Button id="Button1" onClick="Button1_Click" Text="Get Authorisation URL" runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox1" Width=1300 runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox2" Width=900 runat="server" />
   <br/> <br/>
   <asp:Button id="Button2" onClick="Button2_Click" Text="Get Access Token" runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox3" Width=900 runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox4" Width=900 runat="server" />
   <br/> <br/>
   <asp:Button id="Button3" onClick="Button3_Click" Text="Get Response" runat="server" />
   <br/> <br/>
   <asp:TextBox id="TextBox5" Width=900 runat="server" />
   </form>
</body>
</html>



© 2022 Better Solutions Limited. All Rights Reserved. © 2022 Better Solutions Limited TopPrevNext