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;
}