public void Stop() { if (request != null) { request.Abort(); } }
public static bool Test(string url, string proxyaddress, string proxyport, string username, string password, bool isProxy) { try { System.Net.WebProxy proxy = null; if (isProxy) { proxy = new System.Net.WebProxy(proxyaddress + ":" + proxyport, true); if (!string.IsNullOrEmpty(username) && !string.IsNullOrEmpty(password)) { proxy.Credentials = new System.Net.NetworkCredential(username, password); } else { //proxy.Credentials = new System.Net; } } System.Net.WebRequest req = System.Net.WebRequest.Create(url); req.Timeout = 10000; req.Proxy = proxy; req.GetResponse(); req.Abort(); req = null; return(true); } catch (Exception ex) { LogHelper.WriteLog("测试代理服务器失败:代理服务器:" + proxyaddress + ":" + proxyport + ",用户名:" + username + "密码:" + password + Environment.NewLine + "错误:" + ex.Message); return(false); } }
/// <summary> /// 访问URL地址,返回值 /// </summary> /// <param name="url"></param> /// <param name="httpTimeout"></param> /// <param name="postEncoding"></param> /// <returns></returns> public static string CallWeb(string url, int httpTimeout, Encoding postEncoding) { string rStr = ""; System.Net.WebRequest req = null; System.Net.WebResponse resp = null; System.IO.Stream os = null; System.IO.StreamReader sr = null; try { //创建连接 req = System.Net.WebRequest.Create(url); req.ContentType = "application/x-www-form-urlencoded"; req.Method = "GET"; //时间 if (httpTimeout > 0) { req.Timeout = httpTimeout; } //读取返回结果 resp = req.GetResponse(); sr = new System.IO.StreamReader(resp.GetResponseStream(), postEncoding); rStr = sr.ReadToEnd(); int bodystart = rStr.IndexOf("<body>") + 6; //除去<body> int bodylenght = rStr.LastIndexOf("</body>") - bodystart; //除去</body> rStr = rStr.Substring(bodystart, bodylenght).Trim(); //除去空格 } catch { return(rStr); } finally { //关闭资源 if (os != null) { os.Dispose(); os.Close(); } if (sr != null) { sr.Dispose(); sr.Close(); } if (resp != null) { resp.Close(); } if (req != null) { req.Abort(); req = null; } } return(rStr); }
static StackObject *Abort_7(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj) { ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain; StackObject *ptr_of_this_method; StackObject *__ret = ILIntepreter.Minus(__esp, 1); ptr_of_this_method = ILIntepreter.Minus(__esp, 1); System.Net.WebRequest instance_of_this_method = (System.Net.WebRequest) typeof(System.Net.WebRequest).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack)); __intp.Free(ptr_of_this_method); instance_of_this_method.Abort(); return(__ret); }
public virtual void Abort() { _webRequest.Abort(); }