HttpWebRequest和HttpWebResponse用法小结
2011-09-26 21:00
691 查看
/// <summary>
/// 报告系统错误
/// </summary>
/// <param name="ex"></param>
/// <returns></returns>
public static string Sys_ReportError(Exception ex)
{
try
{
//要提交表单的URI字符串
string uriString = "http://localhost/Sys_ReportError.aspx";
HttpContext context = HttpContext.Current;
if (context == null) return string.Empty;
string targetSite = ex.TargetSite.ToString();
string stackTrace = ex.StackTrace;
string friendlyMsg = ex.Message;
string errorPage = context == null || context.Request == null ? "" : context.Request.Url.ToString();
string projectName = Config.Sys_Title();
//要提交的字符串数据
string postString = "targetSite=" + HttpUtility.UrlEncode(targetSite);
postString += "&stackTrace=" + HttpUtility.UrlEncode(stackTrace);
postString += "&friendlyMsg=" + HttpUtility.UrlEncode(friendlyMsg);
postString += "&errorPage=" + HttpUtility.UrlEncode(errorPage);
postString += "&projectName=" + HttpUtility.UrlEncode(projectName);
postString += "&key=" + "";
HttpWebRequest webRequest = null;
StreamWriter requestWriter = null;
string responseData = "";
webRequest = System.Net.WebRequest.Create(uriString) as HttpWebRequest;
webRequest.Method = "POST";
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 1000 * 60;
webRequest.ContentType = "application/x-www-form-urlencoded";
//POST the data.
requestWriter = new StreamWriter(webRequest.GetRequestStream());
try
{
requestWriter.Write(postString);
}
catch (Exception ex2)
{
return "连接错误";
}
finally
{
requestWriter.Close();
requestWriter = null;
}
responseData = WebResponseGet(webRequest);
webRequest = null;
return responseData;
}
catch
{
return "未知错误";
}
}
相关文章推荐
- HttpWebRequest和HttpWebResponse用法小结
- HttpWebRequest和HttpWebResponse用法小结
- HttpWebRequest 与 HttpWebResponse 的简单用法
- HttpWebRequest,HttpWebResponse的用法和用途
- HttpWebRequest 与 HttpWebResponse用法 小记
- HttpWebRequest,HttpWebResponse的用法和用途
- c# HttpWebRequest与HttpWebResponse
- C# post xml using HttpWebRequest/Response
- 利用HttpWebRequest和HttpWebResponse获取Cookie
- C# URL返回结果并转换编码 c# HttpWebRequest与HttpWebResponse
- HttpWebRequest出错 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
- C#使用HttpWebRequest与HttpWebResponse模拟用户登录
- Windows Phone网络HttpWebRequest用法
- C# 使用HttpWebRequest,HttpWebResponse 快速验证代理IP是否有用
- [C#]基于HttpWebRequest和HttpWebResponse的自动登录采集
- C#模拟POST提交表单(二)--HttpWebRequest以及HttpWebResponse
- JavaWeb开发知识总结(HttpServletRequest,HttpServletResponse)
- HttpWebRequest、HttpWebResponse简单Demo
- 黄聪:C#模拟网站页面POST数据提交表单(二)--HttpWebRequest以及HttpWebResponse (转)
- HttpRequest与HttpResponse用法助解