服务器拒绝请求码(CHttp请求)
使用HTTP请求目标地址时出现问题描述,,我来为大家讲解一下关于服务器拒绝请求码?跟着小编一起来看一看吧!
服务器拒绝请求码
使用HTTP请求目标地址时出现问题描述,
使用EXE程序,能正常请求目标地址并获取值,代码如下:
///<summary> ///Description:提交请求URL数据 ///</summary> ///<param name="URL">Url地址</param> ///<param name="ArgData">发送的数据</param> ///<param name="Method">Http请求模式(Post/Get)</param> ///<returns>返回窗体内容</returns> public static string RequestUrl(string requestUrl, string postData, HTTPTYPE reqType) { WebClient client = new WebClient(); string IsProxy = System.Configuration.ConfigurationManager.AppSettings["IsProxy"]; if (IsProxy == "true") { string ProxyHost = System.Configuration.ConfigurationManager.AppSettings["ProxyHost"]; if (!string.IsNullOrEmpty(ProxyHost)) { string ProxyPort = System.Configuration.ConfigurationManager.AppSettings["ProxyPort"]; WebProxy p = new WebProxy(); Uri u = new Uri("http://" ProxyHost ":" ProxyPort); p.Address = u;
|
/// <summary> /// WEB请求帮助类 /// </summary> /// <param name="url">请求地址</param> /// <param name="postData">post参数</param> /// <param name="reqType">请求方式</param> /// <returns></returns> public static string webRequset(string requestUrl, string postData,HTTPTYPE reqType) { string str = ""; StringBuilder sb = new StringBuilder(); try { sb.AppendLine("请求 ====> " requestUrl); sb.AppendLine("入参 ====> " postData); WebClient client = new WebClient(); string IsProxy = System.Configuration.ConfigurationManager.AppSettings["IsProxy"]; if (IsProxy == "true") { sb.AppendLine("已启用代理"); string ProxyHost = System.Configuration.ConfigurationManager.AppSettings["ProxyHost"]; if (!string.IsNullOrEmpty(ProxyHost)) { string ProxyPort = System.Configuration.ConfigurationManager.AppSettings["ProxyPort"]; WebProxy p = new WebProxy(); Uri u = new Uri("http://" ProxyHost ":" ProxyPort); p.Address = u; p.BypassProxyOnLocal = true; client.Proxy = p; } } if (reqType == HTTPTYPE.GET) { sb.AppendLine("请求方式 ===> GET"); str = client.DownloadString(string.Format("{0}?{1}", requestUrl, postData)); } else { sb.AppendLine("请求方式 ===> POST"); byte[] bytes = Encoding.UTF8.GetBytes(postData); client.Headers.Add("Content-Type", "application/json"); client.Headers.Add("ContentLength", postData.Length.ToString()); client.Headers.Add("ENCRTYPT_TYPE", "0"); client.Headers.Add("DATA_TYPE", "0"); client.Headers.Add("CHAR_SET", "UTF-8"); client.Headers.Add("MAX_WATI", "6000"); byte[] ret = client.UploadData(requestUrl, "POST", bytes); str = HttpUtility.UrlDecode(ret, System.Text.Encoding.GetEncoding("UTF-8")); } sb.AppendLine("返回 ====> " str); return str; } catch (Exception ex) { sb.AppendLine("异常:" ex.Message.ToString()); return str; } finally { ErrorLog.WriteLog(sb.ToString()); } } |
免责声明:本文仅代表文章作者的个人观点,与本站无关。其原创性、真实性以及文中陈述文字和内容未经本站证实,对本文以及其中全部或者部分内容文字的真实性、完整性和原创性本站不作任何保证或承诺,请读者仅作参考,并自行核实相关内容。文章投诉邮箱:anhduc.ph@yahoo.com