本文整理汇总了C#中System.Net.HttpWebRequest.GetResponse2方法的典型用法代码示例。如果您正苦于以下问题:C# HttpWebRequest.GetResponse2方法的具体用法?C# HttpWebRequest.GetResponse2怎么用?C# HttpWebRequest.GetResponse2使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.HttpWebRequest
的用法示例。
在下文中一共展示了HttpWebRequest.GetResponse2方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DoHttpWebRequest
public static HttpResponse DoHttpWebRequest(HttpWebRequest request, byte[] data)
{
request.UserAgent = HttpUtils.elmcity_user_agent;
try
{
//request.ContentLength = 0;
if (data != null && data.Length > 0)
{
request.ContentLength = data.Length;
var bw = new BinaryWriter(request.GetRequestStream());
bw.Write(data);
bw.Flush();
bw.Close();
}
}
catch (Exception ex_write)
{
GenUtils.PriorityLogMsg("exception", "DoHttpWebRequest: writing data", ex_write.Message + ex_write.InnerException.Message + ex_write.StackTrace);
throw (ex_write);
}
try
{
var response = (HttpWebResponse)request.GetResponse2();
var status = response.StatusCode;
string message = response.StatusDescription;
var headers = new Dictionary<string, string>();
foreach (string key in response.Headers.Keys)
headers[key] = response.Headers[key];
byte[] return_data = GetResponseData(response);
response.Close();
return new HttpResponse(status, message, return_data, headers);
}
catch (Exception ex_read)
{
GenUtils.PriorityLogMsg("exception", "DoHttpWebRequest: reading data", ex_read.Message + ex_read.InnerException.Message + ex_read.StackTrace);
throw (ex_read);
}
}