Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP GET request and XML answer

Tags:

c#

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 ?

like image 882
Jelena Avatar asked Nov 12 '10 23:11

Jelena


People also ask

What is XML request and response?

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.

How do I get HTTP request?

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.

How do I use XMLHttpRequest?

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.

Can Rest return XML?

Data types that REST API can return are as follows: JSON (JavaScript Object Notation) XML. HTML.


1 Answers

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.

like image 83
Jon Skeet Avatar answered Oct 04 '22 00:10

Jon Skeet