|
@ -13,66 +13,7 @@ namespace ICSSoft.FromERP |
|
|
{ |
|
|
{ |
|
|
public class HttpHelper |
|
|
public class HttpHelper |
|
|
{ |
|
|
{ |
|
|
#region Get请求
|
|
|
|
|
|
///// <summary>
|
|
|
|
|
|
///// 发送http Get请求
|
|
|
|
|
|
///// </summary>
|
|
|
|
|
|
///// <param name="url"></param>
|
|
|
|
|
|
///// <returns></returns>
|
|
|
|
|
|
//public static string GetRequest(string url)
|
|
|
|
|
|
//{
|
|
|
|
|
|
// HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
|
|
|
|
|
|
// request.Method = "GET";
|
|
|
|
|
|
// request.ContentType = "application/x-www-form-urlencoded";//链接类型
|
|
|
|
|
|
// string result = GetResponseString(request.GetResponse() as HttpWebResponse);
|
|
|
|
|
|
// return result;
|
|
|
|
|
|
//}
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// 从HttpWebResponse对象中提取响应的数据转换为字符串
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="webresponse"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
public static string GetResponseString(HttpWebResponse webresponse) |
|
|
|
|
|
{ |
|
|
|
|
|
using (Stream s = webresponse.GetResponseStream()) |
|
|
|
|
|
{ |
|
|
|
|
|
StreamReader reader = new StreamReader(s, Encoding.UTF8); |
|
|
|
|
|
return reader.ReadToEnd(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
|
|
public static bool PingTest(string ip) |
|
|
|
|
|
{ |
|
|
|
|
|
System.Net.NetworkInformation.Ping ping = new System.Net.NetworkInformation.Ping(); |
|
|
|
|
|
|
|
|
|
|
|
System.Net.NetworkInformation.PingReply pingStatus = |
|
|
|
|
|
ping.Send(IPAddress.Parse(ip), 1000); |
|
|
|
|
|
|
|
|
|
|
|
if (pingStatus.Status == System.Net.NetworkInformation.IPStatus.Success) |
|
|
|
|
|
{ |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public static bool WebRequestTest(string url) |
|
|
|
|
|
{ |
|
|
|
|
|
try |
|
|
|
|
|
{ |
|
|
|
|
|
System.Net.WebRequest myRequest = System.Net.WebRequest.Create(url); |
|
|
|
|
|
System.Net.WebResponse myResponse = myRequest.GetResponse(); |
|
|
|
|
|
} |
|
|
|
|
|
catch (System.Net.WebException) |
|
|
|
|
|
{ |
|
|
|
|
|
return false; |
|
|
|
|
|
} |
|
|
|
|
|
return true; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// POST请求
|
|
|
/// POST请求
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|