C # simulate Baidu login and reply to the specified website for comment (5 ),

Source: Internet
Author: User

C # simulate Baidu login and reply to the specified website for comment (5 ),

The previous four articles have already completed all the simulated Baidu logon, followed by posting comments on the specified website. Of course, you may also get other information. In fact, these routines are always different, after understanding it, I felt that the request-response function like this was really simple (it was so sad to think of the detour we had taken)

 

Today's detailed review process is not much said. Here we will point out the problems I encountered when writing this function, and these problems have led to a dilemma. (This is mainly about theory. If you have any questions about shoes you don't understand, please comment on them)

First problem: If you use Baidu to log on to the website, the conversion will take place after we have obtained BDUSS. Because the webpage I access will continue to request through BDUSS when I access the homepage to obtain a new BDUSS for this website, this shows that, after so much effort, we only got one key. To open the information door, we also need to open other doors.

So what we want to talk about here is --Logical AnalysisThis is too important. after entering the new website, we need to re-analyze and find the main request response page. Sometimes the webpage jumps multiple times and the information will change as well. If we really want to simulate it completely, we will do a lot of work, so here we only need to find the Request Response pages with the information we need.

For example, if I want to obtain my website's own BUDSS, I will contact the front and back content to see which page uses the new BUDSS. Then I will trace back and sort out the page until I find the corresponding BDUSS page. This process is a matter of patience and care.

The second problem: Cookie! One element above is the absolute condition for determining whether the function can be implemented smoothly. Without these two conditions, it is wrong to write much code!

Therefore, when accessing a new website, you must analyze the new cookies and collect them all. When I write a comment, I get the website verification code. Although I can get it, there is always an error. This is the consequence of not getting the sessionID and cookie. These two items are required to request the verification code of the webpage. If you see your own error, check whether these values are in the cookie collector! Because the website wants to identify whether you are the verification code of the same person and then submit it, it looks like sessionID, so this value is required.

 

The following is the specific implementation code: You don't need to know much about it here. You just need to know that the following code is constantly requesting different pages and then getting a response, after obtaining all the cookies and parameters required on the request verification code page, initiate a request. It is worth noting that each page has a logic, and some unnecessary pages are skipped in the middle, so you should be careful when analyzing them.

/// <Summary>
/// Encapsulate the verification code for obtaining the comment page
/// </Summary>
Public void GetCommentCode (string bookID, string bookLink, HttpHelper helper, PictureBox pictureBox)
{
String inclussmain_do_getbudss = string. Format ("http://passport.zongheng.com/bdpass/crossdomain.do? Bdu = {0} & t = {1} "," bytes + bmU5VmFr ", Utility. GetTimeStamp ());
String url_maindo = string. Format ("http://passport.zongheng.com/pcLogin/main.do? _ T = {0} & source = 0 & bduss = {1} & location = {2} ", Utility. GetTimeStamp ()," KJBRdxvy560zXPcYv0F0AG8JYzkmgGDuRCI7IbDJSriNuXDHx19o ~ M98AjZ7S0JkqCIE4RdROE ~ Region ~ MrWqD9wN7JReLd * YgwzOEXEbT3R8KsUBJvEf3KeZ4vKDOJdCC1yUIg * XdaexZ6hHPNZndvfNGQud3aCgCEnZypWEBYqXIFbiw * Quit ~ WLhAhy ~ Sq0dTs9KM7T84YJKZPA = ", Utility. UrlDecode (" http % 3A % 2F % 2Fwww.zongheng.com % 2F "));
String url_getSession = string. Format ("http://book.zongheng.com/ajax/book.comment.getThreadL1st2.do"); // This page is in response to the sessionID
String postData_Session = string. Format ("bookId = {0} & pagebar = 0 & pageNum = 1 & pageSize = 30", bookID); // obtain sessinID
Helper. GetPageResponse_Get (corrssmain_do_Getbudss, Utility. UrlDecode ("http://passport.zongheng.com /? Location = http % 3A % 2F % 2Fwww.zongheng.com % 2F ")," image/png, image/*; q = 0.8, */*; q = 0.5 ");
Helper. getPageResponse_Get (url_maindo, Utility. urlDecode (bookLink), "text/html, application/xhtml + xml, application/xml; q = 0.9, */*; q = 0.8 ");
Helper. GetPageResponse_Post (url_getSession, postData_Session, bookLink );

// Request the verification code after all cookies are collected
Bitmap bp = helper. GetCode (string. Format ("http://passport.zongheng.com/imgcapt? R = {0} ", Utility. GetTimeStamp (), bookLink );
PictureBox. Image = bp;
}
# Endregion

All right, all the functions of this project are finished here. If you have any questions, please comment on them.

Related Article

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.