本文整理汇总了C#中System.Net.HttpWebResponse类的典型用法代码示例。如果您正苦于以下问题:C# HttpWebResponse类的具体用法?C# HttpWebResponse怎么用?C# HttpWebResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HttpWebResponse类属于System.Net命名空间,在下文中一共展示了HttpWebResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Create
public string Create(string url)
{
try
{
// setup web request to tinyurl
request = (HttpWebRequest)WebRequest.Create(string.Format(TINYURL_ADDRESS_TEMPLATE, url));
request.Timeout = REQUEST_TIMEOUT;
request.UserAgent = USER_AGENT;
// get response
response = (HttpWebResponse)request.GetResponse();
// prase response stream to string
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding(ENCODING_NAME));
// convert the buffer into string and store in content
StringBuilder sb = new StringBuilder();
while (reader.Peek() >= 0)
{
sb.Append(reader.ReadLine());
}
return sb.ToString();
}
catch (Exception)
{
return null;
}
}
开发者ID:TlhanGhun,项目名称:digiTweetSnarlEdition,代码行数:29,代码来源:TinyUrlClient.cs
示例2: Download
public static void Download()
{
using (WebClient wcDownload = new WebClient())
{
try
{
webRequest = (HttpWebRequest)WebRequest.Create(optionDownloadURL);
webRequest.Credentials = CredentialCache.DefaultCredentials;
webResponse = (HttpWebResponse)webRequest.GetResponse();
Int64 fileSize = webResponse.ContentLength;
strResponse = wcDownload.OpenRead(optionDownloadURL);
strLocal = new FileStream(optionDownloadPath, FileMode.Create, FileAccess.Write, FileShare.None);
int bytesSize = 0;
byte[] downBuffer = new byte[2048];
downloadForm.Refresh();
while ((bytesSize = strResponse.Read(downBuffer, 0, downBuffer.Length)) > 0)
{
strLocal.Write(downBuffer, 0, bytesSize);
PercentProgress = Convert.ToInt32((strLocal.Length * 100) / fileSize);
pBar.Value = PercentProgress;
pLabel.Text = "Downloaded " + strLocal.Length + " out of " + fileSize + " (" + PercentProgress + "%)";
downloadForm.Refresh();
}
}
catch { }
finally
{
webResponse.Close();
strResponse.Close();
strLocal.Close();
extractAndCleanup();
downloadForm.Hide();
}
}
}
开发者ID:bodiroga,项目名称:Avalon,代码行数:35,代码来源:checkForUpdate.cs
示例3: DisposeObject
private static void DisposeObject(ref HttpWebRequest request, ref HttpWebResponse response,
ref Stream responseStream, ref StreamReader reader)
{
if (request != null)
{
request = null;
}
if (response != null)
{
response.Close();
response = null;
}
if (responseStream != null)
{
responseStream.Close();
responseStream.Dispose();
responseStream = null;
}
if (reader != null)
{
reader.Close();
reader.Dispose();
reader = null;
}
}
开发者ID:superhappy123,项目名称:Test,代码行数:25,代码来源:WebUrlRead.cs
示例4: HttpResponse
public HttpResponse(HttpWebResponse httpWebResponse)
{
CharacterSet = httpWebResponse.CharacterSet;
ContentEncoding = httpWebResponse.ContentEncoding;
ContentLength = httpWebResponse.ContentLength;
ContentType = httpWebResponse.ContentType;
//Cookies = httpWebResponse.Cookies;
Headers = httpWebResponse.Headers;
//IsFromCache = httpWebResponse.IsFromCache;
//IsMutuallyAuthenticated = httpWebResponse.IsMutuallyAuthenticated;
//LastModified = httpWebResponse.LastModified;
Method = httpWebResponse.Method;
//ProtocolVersion = httpWebResponse.ProtocolVersion;
//ResponseUri = httpWebResponse.ResponseUri;
//Server = httpWebResponse.Server;
HttpStatusCode = (int)httpWebResponse.StatusCode;
StatusDescription = httpWebResponse.StatusDescription;
}
开发者ID:soto,项目名称:EventStore,代码行数:25,代码来源:HttpResponse.cs
示例5: CouchResponse
public CouchResponse(HttpWebResponse response)
{
responseString = response.GetResponseString();
statusCode = response.StatusCode;
statusDescription = response.StatusDescription;
etag = response.Headers["ETag"];
}
开发者ID:Rychard,项目名称:LoveSeat,代码行数:7,代码来源:CouchResponse.cs
示例6: DisneyPostRequest
public DisneyPostRequest(String url, AuthToken token, String partySize, String mealPeriod, String searchDate)
{
String parameters = "grant_type=assertion&assertion_type=public&client_id=WDPRO-MOBILE.CLIENT-PROD&partySize=" + partySize + "&mealPeriod=" + mealPeriod + "&searchDate=" + searchDate;
IDisneyReservationRequest disneyRequest = this;
HttpWebRequest request = disneyRequest.setHeadersWithAuthorization(url, token);
HttpWebResponse response = disneyRequest.makeReservationRequest(request, parameters);
try
{
_response = response;
String responseMessage = disneyRequest.returnResponse(response);
ResponseMessage = responseMessage;
WebHeaderCollection responseHeaders = response.Headers;
_reservationUrl = responseHeaders.Get("Location");
}
catch (NullReferenceException err)
{
Console.WriteLine(err.Message);
}
DisneyGetRequest reservationRequest = new DisneyGetRequest(_reservationUrl, token);
ResponseMessage = reservationRequest.ResponseMessage;
}
开发者ID:allenmichael,项目名称:DisneyTableReservation,代码行数:25,代码来源:DisneyPostRequest.cs
示例7: NetworkDirectWebResponse
/// <summary>
/// Initializes a new instance of the <see cref="NetworkDirectWebResponse"/> class.
/// </summary>
/// <param name="requestUri">The request URI.</param>
/// <param name="response">The response.</param>
internal NetworkDirectWebResponse(Uri requestUri, HttpWebResponse response)
: base(requestUri, response) {
Requires.NotNull(requestUri, "requestUri");
Requires.NotNull(response, "response");
this.httpWebResponse = response;
this.responseStream = response.GetResponseStream();
}
开发者ID:437072341,项目名称:dotnetopenid,代码行数:12,代码来源:NetworkDirectWebResponse.cs
示例8: NetworkDirectWebResponse
/// <summary>
/// Initializes a new instance of the <see cref="NetworkDirectWebResponse"/> class.
/// </summary>
/// <param name="requestUri">The request URI.</param>
/// <param name="response">The response.</param>
internal NetworkDirectWebResponse(Uri requestUri, HttpWebResponse response)
: base(requestUri, response) {
Contract.Requires<ArgumentNullException>(requestUri != null);
Contract.Requires<ArgumentNullException>(response != null);
this.httpWebResponse = response;
this.responseStream = response.GetResponseStream();
}
开发者ID:enslam,项目名称:dotnetopenid,代码行数:12,代码来源:NetworkDirectWebResponse.cs
示例9: WebResponseEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="WebResponseEventArgs"/> class
/// with the specified web response.
/// </summary>
/// <param name="response">The HTTP web response.</param>
/// <exception cref="ArgumentNullException">If <paramref name="response"/> is <c>null</c>.</exception>
public WebResponseEventArgs(HttpWebResponse response)
{
if (response == null)
throw new ArgumentNullException("response");
_response = response;
}
开发者ID:justinsaraceno,项目名称:openstack.net,代码行数:13,代码来源:WebResponseEventArgs.cs
示例10: AddToCache
public static CacheMetaData AddToCache(HttpWebResponse resp, string file)
{
string md5 = resp.Headers[HttpResponseHeader.ETag].Split(':')[0].Substring(1);
CacheMetaData meta = new CacheMetaData(resp.ContentLength, md5.ToByteArray());
meta.Save(file);
return meta;
}
开发者ID:aeo24,项目名称:WoWMap,代码行数:7,代码来源:CDNCache.cs
示例11: GetContent
public virtual string GetContent(HttpWebResponse webResp, Encoding encoding)
{
string content = null;
var countTry = 3;
var repeat = true;
while (repeat && countTry > 0)
try
{
var responseStream = webResp.GetResponseStream();
responseStream.ReadTimeout = 8000;
using (var sr = new StreamReader(responseStream, encoding))
{
content = sr.ReadToEnd();
repeat = false;
}
}
catch (WebException exWeb)
{
countTry--;
File.AppendAllText("log.txt", exWeb.Message + Environment.NewLine);
File.AppendAllText("log.txt", "++" + Environment.NewLine);
File.AppendAllText("log.txt", exWeb.Status.ToString() + Environment.NewLine);
File.AppendAllText("log.txt", "++" + Environment.NewLine);
File.AppendAllText("log.txt", "GetContent" + Environment.NewLine);
File.AppendAllText("log.txt", "------" + Environment.NewLine);
var webReq = GetHttpWebReq(url);
webResp = GetHttpWebResp(webReq);
}
return content;
}
开发者ID:ruslanruslanruslan,项目名称:Parser,代码行数:30,代码来源:WebClAlwaysNewProxy.cs
示例12: HttpResponse
public HttpResponse(HttpWebRequest con)
{
this.con = con;
this.rsp = (HttpWebResponse)con.GetResponse();
this.stream = rsp.GetResponseStream();
this.reader = new StreamReader(stream, Encoding.UTF8);
}
开发者ID:MasterGao,项目名称:DevWinFormFrame,代码行数:7,代码来源:HttpResponse.cs
示例13: ExtractFromResponse
private PageInfo ExtractFromResponse(HttpWebResponse response)
{
var info = new PageInfo();
using (var responseStream = response.GetResponseStream())
{
var htmlDocument = new HtmlDocument();
htmlDocument.Load(responseStream);
htmlDocument.OptionFixNestedTags = true;
var quote = htmlDocument.DocumentNode
.SelectSingleNode("//body")
.SelectNodes("//p").Where(a => a.Attributes.Any(x => x.Name == "class" && x.Value == "qt"))
.SingleOrDefault();
var title = htmlDocument.DocumentNode
.SelectSingleNode("//title");
//Quote might not be found, bash.org doesn't have a 404 page
if (quote == null || title == null)
{
return null;
}
//Strip out any HTML that isn't defined in the WhiteList
SanitizeHtml(quote);
info.Quote = quote.InnerHtml;
info.PageURL = response.ResponseUri.AbsoluteUri;
info.QuoteNumber = title.InnerHtml;
}
return info;
}
开发者ID:paulduran,项目名称:blaze,代码行数:34,代码来源:BashQDBContentProvider.cs
示例14: CheckUpdate
public static void CheckUpdate()
{
kIRCVersionChecker.Init();
Updater = (HttpWebRequest)HttpWebRequest.Create(update_checkerurl);
Updater_Response = (HttpWebResponse)Updater.GetResponse();
if (Updater_Response.StatusCode == HttpStatusCode.OK)
{
Rocket.Unturned.Logging.Logger.Log("kIRC: Contacting updater...");
Stream reads = Updater_Response.GetResponseStream();
byte[] buff = new byte[10];
reads.Read(buff, 0, 10);
string ver = Encoding.UTF8.GetString(buff);
ver = ver.ToLower().Trim(new[] { ' ', '\r', '\n', '\t' }).TrimEnd(new[] { '\0' });
if (ver == VERSION.ToLower().Trim())
{
Rocket.Unturned.Logging.Logger.Log("kIRC: This plugin is using the latest version!");
}
else
{
Rocket.Unturned.Logging.Logger.LogWarning("kIRC Warning: Plugin version mismatch!");
Rocket.Unturned.Logging.Logger.LogWarning("Current version: "+VERSION+", Latest version on repository is " + ver + ".");
}
}
else
{
Rocket.Unturned.Logging.Logger.LogError("kIRC Error: Failed to contact updater.");
}
Updater.Abort();
Updater = null;
Updater_Response = null;
lastchecked = DateTime.Now;
}
开发者ID:lavery98,项目名称:Rocket_kIRC,代码行数:34,代码来源:kIRCVersionChecker.cs
示例15: CreatePagSeguroServiceException
/// <summary>
///
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
internal static PagSeguroServiceException CreatePagSeguroServiceException(HttpWebResponse response)
{
if (response == null)
throw new PagSeguroServiceException("response answered with null value");
if (response.StatusCode == HttpStatusCode.OK)
throw new ArgumentException("response.StatusCode must be different than HttpStatusCode.OK", "response");
using (XmlReader reader = XmlReader.Create(response.GetResponseStream()))
{
switch (response.StatusCode)
{
case HttpStatusCode.BadRequest:
List<ServiceError> errors = new List<ServiceError>();
try
{
ErrorsSerializer.Read(reader, errors);
}
catch (XmlException e)
{
return new PagSeguroServiceException(response.StatusCode, e);
}
return new PagSeguroServiceException(response.StatusCode, errors);
default:
return new PagSeguroServiceException(response.StatusCode);
}
}
}
开发者ID:danielwolf14,项目名称:bananasfit-web,代码行数:35,代码来源:HttpURLConnectionUtil.cs
示例16: GetNextVisibleTime
/// <summary>
/// Extracts the next visibility time from a web response header.
/// </summary>
/// <param name="response">The web response.</param>
/// <returns>The time of next visibility stored in the header of the response.</returns>
public static DateTime GetNextVisibleTime(HttpWebResponse response)
{
return DateTime.Parse(
response.Headers[Constants.HeaderConstants.NextVisibleTime],
System.Globalization.DateTimeFormatInfo.InvariantInfo,
System.Globalization.DateTimeStyles.AdjustToUniversal);
}
开发者ID:nberardi,项目名称:azure-sdk-for-net,代码行数:12,代码来源:QueueHttpResponseParsers.cs
示例17: Handle
public override void Handle(HttpWebResponse web_response)
{
string str = this.ReadResponse(ref web_response);
if (!set_nucleus_id(str))
throw new RequestException<WebAppPage>("Unable to find nucleus id");
}
开发者ID:ddksaku,项目名称:futbot,代码行数:7,代码来源:WebAppPage.cs
示例18: Parse
/// <summary>
/// Parses HTTP response and creates new instance of this class
/// </summary>
/// <param name="response">HTTP response</param>
/// <returns>New instance of this class</returns>
internal static UploadMappingResults Parse(HttpWebResponse response)
{
UploadMappingResults result = Parse<UploadMappingResults>(response);
if (result.Mappings == null)
result.Mappings = new Dictionary<string, string>();
if (result.JsonObj != null)
{
// parsing message
var message = result.JsonObj.Value<string>("message") ?? string.Empty;
result.Message = message;
// parsing mappings
var mappingsJToken = result.JsonObj["mappings"];
if (mappingsJToken != null)
{
var mappings = mappingsJToken.Children();
foreach(var mapping in mappings)
{
result.Mappings.Add(mapping["folder"].ToString(), mapping["template"].ToString());
}
}
// parsing single mapping
var folder = result.JsonObj.Value<string>("folder") ?? string.Empty;
var template = result.JsonObj.Value<string>("template") ?? string.Empty;
if (!string.IsNullOrEmpty(folder))
result.Mappings.Add(folder, template);
//parsing NextCursor
result.NextCursor = result.JsonObj.Value<string>("next_cursor") ?? string.Empty;
}
return result;
}
开发者ID:cloudinary,项目名称:CloudinaryDotNet,代码行数:40,代码来源:UploadMappingResults.cs
示例19: GetRequest
public bool GetRequest(string url, string referer)
{
bool result = false;
try
{
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US)AppleWebKit/533.4 (KHTML, like Gecko) Chrome/5.0.375.70 Safari/533.4";
httpWebRequest.Referer = referer;
httpWebRequest.Headers.Add("Cache-Control", "max-age=0");
httpWebRequest.Accept = "application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
httpWebRequest.Headers.Add("Accept-Encoding", "gzip,deflate,sdch");
httpWebRequest.Headers.Add("Accept-Language", "ru-RU,ru;q=0.8,en-US;q=0.6,en;q=0.4");
httpWebRequest.Headers.Add("Accept-Charset", "windows-1251,utf-8;q=0.7,*;q=0.3");
httpWebRequest.AllowAutoRedirect = this.AutoRedirect;
httpWebRequest.CookieContainer = this.Cookie;
this.HttpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();
this.GetCookiesFromResponse();
result = true;
}
catch
{
result = false;
return result;
}
return result;
}
开发者ID:OleksandrKulchytskyi,项目名称:VkManager,代码行数:26,代码来源:MyHttpRequests.cs
示例20: GetContent
public string GetContent(HttpWebResponse webResp, Encoding encoding)
{
string content = null;
var countTry = 3;
var repeat = true;
while (repeat && countTry > 0 && webResp != null)
try
{
var responseStream = webResp.GetResponseStream();
responseStream.ReadTimeout = 8000;
using (var sr = new StreamReader(responseStream, encoding))
{
content = sr.ReadToEnd();
webResp = null;
if (content.Equals("обновите страницу, пожалуйста"))
throw new WebException("ParsersChe error: Proxy no Russian");
repeat = false;
}
}
catch (WebException exWeb)
{
countTry--;
content = null;
Log(exWeb, "GetContent");
var webReq = GetHttpWebReqNewProxy(url);
if (webReq != null)
webResp = GetHttpWebResp(webReq);
}
return content;
}
开发者ID:ruslanruslanruslan,项目名称:Parser,代码行数:31,代码来源:WebClProxy.cs
注:本文中的System.Net.HttpWebResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论