TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
C# Corner
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
How to Call Rest API in ASP.NET
Pintoo Yadav
Nov 24
2015
Code
1.1
k
0
1
facebook
twitter
linkedIn
Reddit
WhatsApp
Email
Bookmark
expand
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
;
}
}
}
}
API
REST API
ASP.NET