Set Httponlycookie solve MSHTML programming cannot get captcha picture stream

Source: Internet
Author: User
Tags set cookie

Recently to customers to do the project has a new demand, customers need to open the Internet Explorer to do automatic login, log on the page of the god Beast Verification code. The solution to the verification code is to find a third-party platform to code. So there is a problem, how to pass the correct verification code to the third-party coding platform.

As we all know, the verification code is randomly generated, each time the URL of the image will change, so that the path to the third party, the picture is not the map on the page. So I thought of two ways to solve this problem:

1. Intercept the verification code by intercepting it and then pass it to the third party to play the code.

2. Grab the IE cookie and all feature parameters and use these parameters to initiate a request simulation refresh verification code.

Because of the way 1 I Caishuxueqian, had not studied this aspect related knowledge, then decisively abandoned, decided to take plan B.

Using mode 2 o'clock a problem was found, SessionID set the HttpOnly, and this setting allows us to read the HttpOnly cookie directly through the interface. This cannot be disguised as IE browser to refresh the verification code. Because there is no SessionID, The server does not know me. So the change of thinking, decided to set up a good Internet Explorer cookie and then open the site, so that the server can know me. To know me is good to do, and then to complete the simulation to refresh the verification code problem. Start again after a different idea:

1. All cookies on the site, including HttpOnly, are first requested through HttpRequest.

2. Call Wininet.dll to Internet Explorer to set the cookie we get. Attach the core code of the set cookie (online search, if there is infringement, please forgive me)

Private Const intInternet_cookie_httponly =0x00002000; [DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError =true)]        Static extern BOOLInternetgetcookieex (stringPchurl,stringPchcookiename, StringBuilder Pchcookiedata,refSystem.UInt32 Pcchcookiedata,intdwFlags, IntPtr lpreserved); [DllImport ("Wininet.dll", CharSet = CharSet.Auto, SetLastError =true)]        Static extern intInternetsetcookieex (stringLpszurl,stringLpszcookiename,stringLpszcookiedata,intdwFlags, IntPtr dwreserved); Private Static stringGetCookies (stringURL) {            UINTDataSize = the; StringBuilder Cookiedata=NewStringBuilder ((int) datasize); if(! Internetgetcookieex (URL,NULL, Cookiedata,refDataSize,0x2000, IntPtr.Zero)) {                if(DataSize <0)                    return NULL; Cookiedata=NewStringBuilder ((int) datasize); if(! Internetgetcookieex (URL,NULL, Cookiedata,refDataSize,0x00002000, IntPtr.Zero)) return NULL; }            returncookiedata.tostring (); }         Public Static stringSetcookieforie (stringURL, cookiecollection cookiestring,stringPath ="/")        {            Try            {                foreach(Cookie Cinchcookiestring) {                    stringName =C.name; stringValue = C.value +"; expires="+ DateTime.Now.AddDays (1). ToString ("R");                Internetsetcookieex (URL, name, value, Internet_cookie_httponly, IntPtr.Zero); }                returngetcookies (URL); }            Catch(Exception) {return "false"; Throw; }        }

3. Set the cookie to start IE open the website, the use of SessionID is we set up, and then use Httprequst request to refresh the verification code to get the picture stream, to third-party platform to play code to get results, to perform login, problem solving.

I adopted the solution is the simulation refresh verification code, if there are other small partners read this article has not understood, welcome message, please light spray.

Set Httponlycookie solve MSHTML programming cannot get captcha picture stream

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.