/// <Summary>
/// Execute the request connection to obtain the remote resource and return a string
/// </Summary>
/// <Param name = "url"> Remote resource connection </param>
/// <Param name = "encode"> encoding format (default = "") </param>
/// <Returns> returns the obtained string </returns>
Public static string httpwebresponsestring (string URL, string encode)
{
String STR = "";
Try
{
Httpwebrequest httprequest = (httpwebrequest) webrequest. Create (URL );
Httprequest. useragent = @ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 2.0.40607;. Net CLR 1.1.4322 )";
Httpwebresponse httpresponse = (httpwebresponse) httprequest. getresponse ();
If (httprequest. haveresponse)
{
Streamreader SR;
If (encode! = NULL & encode! = "")
{
Sr = new streamreader (httpresponse. getresponsestream (), encoding. getencoding (encode ));
}
Else
{
Sr = new streamreader (httpresponse. getresponsestream (), encoding. Default );
}
STR = Sr. readtoend ();
Sr. Close ();
Httpresponse. Close ();
}
}
Catch (exception ex)
{
Ilog. systemlog (URL "logs *** messages" ex. Message );
}
Return STR;
}
Or
/// <Summary>
/// Execute the request connection to obtain the remote resource and return a string
/// </Summary>
/// <Param name = "url"> Remote resource connection </param>
/// <Param name = "encode"> encoding format (default = "") </param>
/// <Returns> returns the obtained string </returns>
Public static string httpwebresponsestring (string URL, string encode)
{
String STR = "";
Try
{
Httpwebrequest httprequest = (httpwebrequest) webrequest. Create (URL );
Httprequest. useragent = @ "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; sv1;. Net CLR 2.0.40607;. Net CLR 1.1.4322 )";
Httpwebresponse httpresponse = (httpwebresponse) httprequest. getresponse ();
If (httprequest. haveresponse)
{
Streamreader SR;
If (encode! = NULL & encode! = "")
{
Sr = new streamreader (httpresponse. getresponsestream (), encoding. getencoding (encode ));
}
Else
{
Sr = new streamreader (httpresponse. getresponsestream (), encoding. Default );
}
STR = Sr. readtoend ();
Sr. Close ();