I am new to C#, I need to send HTTP GET request and read answer. I am familiar with Java and easy can do it URLConnection class but I don't know in c#. Can anybody help ?
XML request and response support consists of two main functions: The XML parsing function parses an inbound XML request message and maps XML elements to a fixed format COMMAREA. See XML message formats for a sample of a request message in XML format.
To make an HTTP call in Ajax, you need to initialize a new XMLHttpRequest() method, specify the URL endpoint and HTTP method (in this case GET). Finally, we use the open() method to tie the HTTP method and URL endpoint together and call the send() method to fire off the request.
To send an HTTP request, create an XMLHttpRequest object, open a URL, and send the request. After the transaction completes, the object will contain useful information such as the response body and the HTTP status of the result.
Data types that REST API can return are as follows: JSON (JavaScript Object Notation) XML. HTML.
The simplest way is to use WebClient
:
WebClient client = new WebClient();
string text = client.DownloadString(url);
(That's the synchronous form; it also supports asynchronous requests.)
For more control you might want to use HttpWebRequest
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With