Verification code for cross-origin access)

Source: Internet
Author: User
Method 1:

1. Request the home page to obtain the cookie and save the cookie for backup (Note: session is also a cookie)
2. Request an additional code and display it on your own page. Note that when requesting an additional code, you must use the Cookie obtained in step 1 to request it, after the request is complete, if a new Cookie exists, it will be saved.
3. manually enter the additional code and post it to the final page.
------------------------------------------------------------------------------
Method 2:

1. First, you need to obtain cookies from the target website. You can use different methods for different websites.
Generally, you need to first request the page where the verification code is located, so that the server will write the cookies to your container.
Of course, you can also obtain the cookie that has been stored in IE from the local cache, but this is very easy on the. net3.0 and later platforms. on platforms lower than 3.0, you need to call APIs on the platform to obtain the cookie.
2. Simple:

In your code, request the page where the image is located before requesting it. Of course, when you request an image, you must specify the same cookiecontainer object.

 

 

Httpwebrequest request = (httpwebrequest) webrequest. Create (URL );
Httpcontext. Current. session ["pagecookie"] = Req. cookiecontainer. getcookieheader (New uri ("Host of the cookie on the requested site ")));
--------------------------------------------
When you need to append a cookie next time:
Httpwebrequest Req = (httpwebrequest) webrequest. Create (URL );
Req. headers. Add ("Cookie:" + httpcontext. Current. session ["pagecookie"]. tostring ());

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.