C # obtain the website Verification Code Image

Source: Internet
Author: User

 

 

Code

 /// <Summary>
/// Obtain the webpage Verification Code
/// </Summary>
/// <Param name = "server"> server address </param>
/// <Param name = "url"> webpage address </param>
/// <Param name = "byterequest"> byte array, storing image bytes </param>
/// <Param name = "cookie"> the temporary sessionid (temporary cookie value) that the website assigns to the customer is not a real cookie </param>
/// <Param name = "Header"> </param>
/// <Returns> binary array of the image </returns>
Public static byte [] gethtmlbytes (string server, string URL, byte [] byterequest, string cookie, out string header)
{
Long contentlength;
Httpwebrequest;
Httpwebresponse webresponse;
Stream getstream;

Httpwebrequest = (httpwebrequest) httpwebrequest. Create (URL );
Cookiecontainer CO = new cookiecontainer ();
CO. setcookies (New uri (server), cookie );
Httpwebrequest. cookiecontainer = Co;
Httpwebrequest. contenttype = "application/X-WWW-form-urlencoded ";
Httpwebrequest. method = "Post ";
Httpwebrequest. contentlength = byterequest. length;
Stream stream;
Stream = httpwebrequest. getrequeststream ();
Stream. Write (byterequest, 0, byterequest. Length );
Stream. Close ();
Webresponse = (httpwebresponse) httpwebrequest. getresponse ();
Header = webresponse. headers. tostring ();
Getstream = webresponse. getresponsestream ();
Contentlength = webresponse. contentlength;

Byte [] outbytes = new byte [contentlength];
Outbytes = readfully (getstream );
Getstream. Close ();
Return outbytes;
}

 

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.