using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Data;
using System.Data.Common;
using Golive_Web.Controller;
namespace Golive.Controller
{
public class APITEXT
{
Database database = new Database("GoliveAPI");
public DataTable GetAPI()
{
DbCommand cmd = database.GetStoredPocCommand("SP_TExt");
DataTable dtApi = database.ExecuteDataTable(cmd);
return dtApi;
}
public string GetData(String mobileNo, String ID, String APILink)
{
try
{
string XML = "<AccDtls>" + "<Request>" + "<RequestUUID>Req_" + ID + "</RequestUUID>" + "<ServiceRequestId>AcctInq</ServiceRequestId>" + "<ServiceRequestVersion>10.2</ServiceRequestVersion>" + "<ChannelId>CTS</ChannelId>" + "<AccID>" + mobileNo + "</AccID> " + "</Request>" + "</AccDtls>";
const string url = "http://100.98.2.208:6070/rbl/CTSFin";
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);
request.ContentType = "application/xml"; //set the content type to JSON
request.Method = "POST"; //make an HTTP POST
#
region test# endregion
using(var streamWriter = new StreamWriter(request.GetRequestStream()))
{
var resToWrite = XML;
streamWriter.Write(resToWrite);
streamWriter.Flush();
streamWriter.Close();
}
// Get the response.
WebResponse response = request.GetResponse();
var streamReader = new StreamReader(response.GetResponseStream());
string result = streamReader.ReadToEnd();
return result;
}
catch (Exception)
{
throw;
}
}
}
}In this code snippet you will learn how to call rest API in ASP.NET.
