C # dismounting shoppers

Source: Internet
Author: User

Httpwebrequest req;
Httpwebresponse myresp;

// Determine whether the product corresponding to the URL exists. If the product exists, the system returns true or false. If the product does not exist, the system returns false.

Public bool geturltorf (string linkurl, string errurl, long Leng, string neirong)
{
Bool justinfo = false;
Req = (httpwebrequest) webrequest. Create (linkurl );
Req. method = "get ";
Req. allowautoredirect = false;
Try
{
Myresp = (httpwebresponse) Req. getresponse ();
If (Leng! = 0)
{
// Determine whether the product is valid Based on the Content size.
Long Content = myresp. contentlength;
If (content <Leng)
{
Justinfo = true;
}

}
Else
{

// Determine whether the product is valid Based on the jump page
If (myresp. statuscode = httpstatuscode. Redirect)
{
String redirecturl = myresp. getResponseHeader ("location"). tolower ();
If (redirecturl = errurl. tolower ())
{
Justinfo = true;
}

}
// Determine whether the product is valid Based on the content keyword
Else
{
Stream mystream = (Stream) Req. getresponse (). getresponsestream ();
Streamreader mr = new streamreader (mystream, encoding. getencoding ("gb2312 "));
If (MR. readtoend (). indexof (neirong)> = 0 & neirong. Trim ()! = "")
{
Justinfo = true;
// Console. writeline ("found ");
}
Else if (New streamreader (mystream, encoding. getencoding ("UTF-8"). readtoend (). indexof (neirong)> = 0 & neirong. Trim ()! = "")
{
Justinfo = true;
}
}
}
}
Catch (system. Exception ex)
{
Console. writeline (ex. Message );
Justinfo = true;
// Console. writeline (linkurl );
}
Return justinfo;
}

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.