5 Kinds of request-response methods provided by. Net

Source: Internet
Author: User

. NET provides three basic methods and two underlying methods to send HTTP requests and receive HTTP responses, which allow us to mimic the way in which a Web page is accessed by entering a URL address in the browser's address bar. We send an HTTP request to receive the response returned by the server (usually an HTML page). From this to the resulting web page analysis, such as doing automated testing, or crawl the page you are interested in, and then put into their own programs, in short, the application of a lot, I can think of, for the time being so much.

The five methods are:

1.WebClient

2.webrequest-webresponse

3.httpwebrequest-httpwebresponse

4.TcpClient

5.Socket

The first three are relatively simple, the latter two are relatively lower

This paper first WebClient, relatively simple, directly on the code

C # code
  1. Using System;
  2. Using System.Collections.Generic;
  3. Using System.Linq;
  4. Using System.Text;
  5. Using System.Net;
  6. Namespace Webclienttest
  7. {
  8. Class Program
  9. {
  10. static void Main (string[] args)
  11. {
  12. string uri="http://starnc.iteye.com/blog/404768";
  13. WebClient wc=New WebClient ();
  14. Console.WriteLine ("Sending an HTTP Get request to" +uri);
  15. byte[] BRESPONSE=WC.  Downloaddata (URI);
  16. string strresponse=encoding.utf8.getstring (Bresponse);
  17. Console.WriteLine ("HTTP response is:");
  18. Console.WriteLine (Strresponse);
  19. }
  20. }
  21. }

Get results such as



This is what we get from the Web source file, and you directly in IE to access the URL of the page to get the same result, with this you can do what you like to do.

This article refers to the ". NET Software Automation testing Way", a good book, you should see.

5 Kinds of request-response methods provided by. Net

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.