Hi makumbi,
Check this example. Now please take its reference and correct your code.
Here in the example i have hard coded the values to pass the json to handler. You need to get the json from the api.
Namespaces
C#
using System.Net;
using System.Web.Script.Serialization;
VB.Net
Imports System.Net
Imports System.Web.Script.Serialization
Code
C#
protected void Button1_Click(object sender, EventArgs e)
{
Product product = new Product();
product.status = "SUCCESSFUL";
product.msisdn = "256782123456";
product.initiation_date = Convert.ToDateTime("2019-10-21 09:03:03");
product.completion_date = Convert.ToDateTime("2019-10-21 09:03:22");
product.amount = 20000;
product.receipt_number = "1587906379";
product.reference_code = "c1a943f6-3f1aa162-95434a95-ef93f253-1aa43dc7";
JavaScriptSerializer js = new JavaScriptSerializer();
// Get the Json response from the api.
string response = js.Serialize(product);
string responseData = (new WebClient()).DownloadString("http://localhost:54496/Handler.ashx?Json=" + response);
if (responseData != "")
{
MsgboxAsync("Hey!, Yr subscription IS BEING WORKED UPON THANK YOU", "Alright");
}
}
public class Product
{
public string status { get; set; }
public string msisdn { get; set; }
public DateTime initiation_date { get; set; }
public DateTime completion_date { get; set; }
public decimal amount { get; set; }
public string receipt_number { get; set; }
public string reference_code { get; set; }
}
VB.Net
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim product As Product = New Product()
product.status = "SUCCESSFUL"
product.msisdn = "256782123456"
product.initiation_date = Convert.ToDateTime("2019-10-21 09:03:03")
product.completion_date = Convert.ToDateTime("2019-10-21 09:03:22")
product.amount = 20000
product.receipt_number = "1587906379"
product.reference_code = "c1a943f6-3f1aa162-95434a95-ef93f253-1aa43dc7"
Dim js As JavaScriptSerializer = New JavaScriptSerializer()
Dim response As String = js.Serialize(product)
Dim responseData As String = (New WebClient()).DownloadString("http://localhost:54496/Handler.ashx?Json=" & response)
If responseData <> "" Then
MsgboxAsync("Hey!, Yr subscription IS BEING WORKED UPON THANK YOU", "Alright")
End If
End Sub
Public Class Product
Public Property status As String
Public Property msisdn As String
Public Property initiation_date As DateTime
Public Property completion_date As DateTime
Public Property amount As Decimal
Public Property receipt_number As String
Public Property reference_code As String
End Class
Generic Handler
C#
<%@ WebHandler Language="C#" Class="Handler" %>
using System;
using System.Web;
using System.Web.SessionState;
using System.Web.Script.Serialization;
public class Handler : IHttpHandler, IRequiresSessionState
{
public void ProcessRequest(HttpContext context)
{
if (context.Request.QueryString["Json"] != null)
{
string json = context.Request.QueryString["Json"];
JavaScriptSerializer js = new JavaScriptSerializer();
Product product = js.Deserialize<Product>(json);
string y = product.status;
string w = product.reference_code;
string output = "";
if (y == "PENDING")
{
output = "Hey!, Yr subscription IS BEING WORKED UPON THANK YOU";
}
context.Response.ContentType = "text/plain";
context.Response.Write(output);
}
}
public bool IsReusable
{
get
{
return false;
}
}
public class Product
{
public string status { get; set; }
public string msisdn { get; set; }
public DateTime initiation_date { get; set; }
public DateTime completion_date { get; set; }
public decimal amount { get; set; }
public string receipt_number { get; set; }
public string reference_code { get; set; }
}
}
VB.Net
<%@ WebHandler Language="VB" Class="Handler" %>
Imports System
Imports System.Web
Imports System.Web.Script.Serialization
Public Class Handler : Implements IHttpHandler
Public Sub ProcessRequest(ByVal context As HttpContext) Implements IHttpHandler.ProcessRequest
If context.Request.QueryString("Json") IsNot Nothing Then
Dim json As String = context.Request.QueryString("Json")
Dim js As JavaScriptSerializer = New JavaScriptSerializer()
Dim product As Product = js.Deserialize(Of Product)(json)
Dim y As String = product.status
Dim w As String = product.reference_code
Dim output As String = ""
If y = "PENDING" Then
output = "Hey!, Yr subscription IS BEING WORKED UPON THANK YOU"
End If
context.Response.ContentType = "text/plain"
context.Response.Write(output)
End If
End Sub
Public ReadOnly Property IsReusable() As Boolean Implements IHttpHandler.IsReusable
Get
Return False
End Get
End Property
Public Class Product
Public Property status As String
Public Property msisdn As String
Public Property initiation_date As DateTime
Public Property completion_date As DateTime
Public Property amount As Decimal
Public Property receipt_number As String
Public Property reference_code As String
End Class
End Class