Click here to Skip to main content
15,887,945 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello Friends,

I want to call My API Link(URL) in C#.net
I is working using System.Process(URL);
But it is open in the Browser, I don't want to open browser.
so how can i call it ?
Please Give me idea...

Thanks
Posted

string apiUrl = "YourAPIURL";

Uri address = new Uri(apiUrl);

// Create the web request
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;

// Set type to POST
request.Method = "GET";
request.ContentType = "text/xml";

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream());

// Console application output
string strOutputXml = reader.ReadToEnd();
}
 
Share this answer
 
If you want to get the HTML code from a URL and process it your self.
Use can use HttpWebRequest to get all text.

C#
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URL);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

if (response.StatusCode == HttpStatusCode.OK)
{
  Stream receiveStream = response.GetResponseStream();
  StreamReader readStream = null;

  if (response.CharacterSet == null)
    readStream = new StreamReader(receiveStream);
  else
    readStream = new StreamReader(receiveStream, Encoding.GetEncoding(response.CharacterSet));

  string data = readStream.ReadToEnd();
  response.Close();
  readStream.Close();
}


And all text will be in string class data
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900