本文整理汇总了C#中System.Net.WebResponse类的典型用法代码示例。如果您正苦于以下问题:C# WebResponse类的具体用法?C# WebResponse怎么用?C# WebResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebResponse类属于System.Net命名空间,在下文中一共展示了WebResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ProcessResponse
/// <summary>
/// Process the web response and output corresponding objects.
/// </summary>
/// <param name="response"></param>
internal override void ProcessResponse(WebResponse response)
{
if (null == response) { throw new ArgumentNullException("response"); }
// check for Server Core, throws exception if -UseBasicParsing is not used
if (ShouldWriteToPipeline && (!UseBasicParsing))
{
VerifyInternetExplorerAvailable(true);
}
Stream responseStream = StreamHelper.GetResponseStream(response);
if (ShouldWriteToPipeline)
{
// creating a MemoryStream wrapper to response stream here to support IsStopping.
responseStream = new WebResponseContentMemoryStream(responseStream, StreamHelper.ChunkSize, this);
WebResponseObject ro = WebResponseObjectFactory.GetResponseObject(response, responseStream, this.Context, UseBasicParsing);
WriteObject(ro);
// use the rawcontent stream from WebResponseObject for further
// processing of the stream. This is need because WebResponse's
// stream can be used only once.
responseStream = ro.RawContentStream;
responseStream.Seek(0, SeekOrigin.Begin);
}
if (ShouldSaveToOutFile)
{
StreamHelper.SaveStreamToFile(responseStream, QualifiedOutFile, this);
}
}
开发者ID:dfinke,项目名称:powershell,代码行数:34,代码来源:InvokeWebRequestCommand.FullClr.cs
示例2: WebResult
/// <summary>
///
/// </summary>
/// <exception cref="System.ArgumentNullException">if response is null.</exception>
/// <param name="response"></param>
public WebResult(WebResponse response)
{
if (response == null) throw new ArgumentNullException(nameof(response));
this.Type = WebResultType.Succeed;
this.Response = response;
}
开发者ID:nokia6102,项目名称:jasily.cologler,代码行数:12,代码来源:WebResult.cs
示例3: ProcessReponse
public void ProcessReponse(List<SearchResultItem> list, WebResponse resp)
{
var response = new StreamReader(resp.GetResponseStream()).ReadToEnd();
var info = JsonConvert.DeserializeObject<BergGetStockResponse>(response, new JsonSerializerSettings()
{
Culture = CultureInfo.GetCultureInfo("ru-RU")
});
if (info != null && info.Resources.Length > 0)
{
foreach (var resource in info.Resources.Where(r => r.Offers != null))
{
foreach (var offer in resource.Offers)
{
list.Add(new SearchResultItem()
{
Article = resource.Article,
Name = resource.Name,
Vendor = PartVendor.BERG,
VendorPrice = offer.Price,
Quantity = offer.Quantity,
VendorId = resource.Id,
Brand = resource.Brand.Name,
Warehouse = offer.Warehouse.Name,
DeliveryPeriod = offer.AveragePeriod,
WarehouseId = offer.Warehouse.Id.ToString()
});
}
}
}
}
开发者ID:softgears,项目名称:PartDesk,代码行数:33,代码来源:BergSearcher.cs
示例4: ExtendedHttpWebResponse
public ExtendedHttpWebResponse(Uri responseUri, WebResponse response, Stream responseStream, CacheInfo cacheInfo)
{
this.responseUri = responseUri;
this.response = response;
this.responseStream = responseStream;
this.cacheInfo = cacheInfo;
}
开发者ID:jogibear9988,项目名称:SharpVectors,代码行数:7,代码来源:ExtendedHttpWebResponse.cs
示例5: GetContent
public override PageContent GetContent(WebResponse p_Response)
{
// Navigate to the requested page using the WebDriver. PhantomJS will navigate to the page
// just like a normal browser and the resulting html will be set in the PageSource property.
m_WebDriver.Navigate().GoToUrl(p_Response.ResponseUri);
// Let the JavaScript execute for a while if needed, for instance if the pages are doing async calls.
//Thread.Sleep(1000);
// Try to retrieve the charset and encoding from the response or body.
string pageBody = m_WebDriver.PageSource;
string charset = GetCharsetFromHeaders(p_Response);
if (charset == null) {
charset = GetCharsetFromBody(pageBody);
}
Encoding encoding = GetEncoding(charset);
PageContent pageContent = new PageContent {
Encoding = encoding,
Charset = charset,
Text = pageBody,
Bytes = encoding.GetBytes(pageBody)
};
return pageContent;
}
开发者ID:acid009,项目名称:abot-phantomjs,代码行数:27,代码来源:JavaScriptContentExtractor.cs
示例6: FromResponse
public static dynamic FromResponse(WebResponse response)
{
using (var stream = response.GetResponseStream())
{
return FromStream(stream);
}
}
开发者ID:Rezura,项目名称:LiveSplit,代码行数:7,代码来源:JSON.cs
示例7: FromWebResponse
/// <summary>
/// 从Response获取错误信息
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
public static WfServiceInvokeException FromWebResponse(WebResponse response)
{
StringBuilder strB = new StringBuilder();
string content = string.Empty;
using (Stream stream = response.GetResponseStream())
{
StreamReader streamReader = new StreamReader(stream, Encoding.UTF8);
content = streamReader.ReadToEnd();
}
if (response is HttpWebResponse)
{
HttpWebResponse hwr = (HttpWebResponse)response;
strB.AppendFormat("Status Code: {0}, Description: {1}\n", hwr.StatusCode, hwr.StatusDescription);
}
strB.AppendLine(content);
WfServiceInvokeException result = new WfServiceInvokeException(strB.ToString());
if (response is HttpWebResponse)
{
HttpWebResponse hwr = (HttpWebResponse)response;
result.StatusCode = hwr.StatusCode;
result.StatusDescription = hwr.StatusDescription;
}
return result;
}
开发者ID:jerryshi2007,项目名称:AK47Source,代码行数:38,代码来源:WfServiceInvokeException.cs
示例8: ParseResponse
public ICommandResponse ParseResponse(WebResponse response)
{
var request = _computeRequestService.GenerateRequest(null, _apiKey);
_authenticator.AuthenticateRequest(WebRequest.Create(""), _base64Secret);//((RestClient)_client).BuildUri((RestRequest)request), _base64Secret);
return _client.Execute<MachineResponse>((RestRequest)request).Data;
}
开发者ID:stephengodbold,项目名称:ninefold-dotnet-api,代码行数:7,代码来源:DestroyVirtualMachine.cs
示例9: WebResponseDetails
/// <summary>
/// Initializes a new instance of the <see cref="WebResponseDetails"/> class.
/// </summary>
/// <param name="webResponse">The web response.</param>
public WebResponseDetails(WebResponse webResponse)
{
if (webResponse == null)
{
throw new ArgumentNullException("webResponse", "Server response could not be null");
}
//
// Copy headers
this.Headers = new Dictionary<string,string>();
if ((webResponse.Headers != null) && (webResponse.Headers.Count > 0))
{
foreach (string key in webResponse.Headers.AllKeys)
this.Headers.Add(key, webResponse.Headers[key]);
}
//
// Copy body (raw)
try
{
StreamReader reader = new StreamReader(webResponse.GetResponseStream(), System.Text.Encoding.Default);
this.Body = reader.ReadToEnd();
}
catch (ArgumentNullException exp_null)
{
//
// No response stream ?
System.Diagnostics.Trace.WriteLine("WebResponse does not have any response stream");
this.Body = string.Empty;
}
}
开发者ID:jasper22,项目名称:Swift.Sharp,代码行数:35,代码来源:WebResponseDetails.cs
示例10: SharpBoxException
internal SharpBoxException(SharpBoxErrorCodes errorCode, Exception innerException, WebRequest request, WebResponse response)
: base(GetErrorMessage(errorCode), innerException)
{
ErrorCode = errorCode;
PostedRequet = request;
DisposedReceivedResponse = response;
}
开发者ID:ridhouan,项目名称:teamlab.v6.5,代码行数:7,代码来源:SharpBoxException.cs
示例11: WebException
public WebException(String msg, Exception inner,
WebExceptionStatus status, WebResponse response)
: base(msg, inner)
{
myresponse = response;
mystatus = status;
}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:7,代码来源:WebException.cs
示例12: ReadAll
private string ReadAll(WebResponse webResponse)
{
using (var reader = new StreamReader(webResponse.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
开发者ID:7digital,项目名称:WebGl-7digital,代码行数:7,代码来源:ApiWrapper.cs
示例13: SetResponse
private void SetResponse(WebResponse response, Stream contentStream)
{
if (null == response) { throw new ArgumentNullException("response"); }
BaseResponse = response;
MemoryStream ms = contentStream as MemoryStream;
if (null != ms)
{
_rawContentStream = ms;
}
else
{
Stream st = contentStream;
if (contentStream == null)
{
st = StreamHelper.GetResponseStream(response);
}
long contentLength = response.ContentLength;
if (0 >= contentLength)
{
contentLength = StreamHelper.DefaultReadBuffer;
}
int initialCapacity = (int)Math.Min(contentLength, StreamHelper.DefaultReadBuffer);
_rawContentStream = new WebResponseContentMemoryStream(st, initialCapacity, null);
}
// set the position of the content stream to the beginning
_rawContentStream.Position = 0;
}
开发者ID:40a,项目名称:PowerShell,代码行数:30,代码来源:WebResponseObject.FullClr.cs
示例14: AirbrakeResponse
/// <summary>
/// Initializes a new instance of the <see cref="AirbrakeResponse"/> class.
/// </summary>
/// <param name="response">The response.</param>
/// <param name="content">The content.</param>
public AirbrakeResponse(WebResponse response, string content)
{
this.log = LogManager.GetLogger(GetType());
this.content = content;
this.errors = new AirbrakeResponseError[0];
if (response != null)
{
// TryGet is needed because the default behavior of WebResponse is to throw NotImplementedException
// when a method isn't overridden by a deriving class, instead of declaring the method as abstract.
this.contentLength = response.TryGet(x => x.ContentLength);
this.contentType = response.TryGet(x => x.ContentType);
this.headers = response.TryGet(x => x.Headers);
this.isFromCache = response.TryGet(x => x.IsFromCache);
this.isMutuallyAuthenticated = response.TryGet(x => x.IsMutuallyAuthenticated);
this.responseUri = response.TryGet(x => x.ResponseUri);
}
try
{
Deserialize(content);
}
catch (Exception exception)
{
this.log.Fatal(f => f(
"An error occurred while deserializing the following content:\n{0}", content),
exception);
}
}
开发者ID:zlx,项目名称:SharpBrake,代码行数:34,代码来源:AirbrakeResponse.cs
示例15: SaveBinaryFile
public static bool SaveBinaryFile(WebResponse response, string FileName)
{
bool Value = true;
byte[] buffer = new byte[1024];
try
{
if (File.Exists(FileName))
File.Delete(FileName);
Stream outStream = File.Create(FileName);
Stream inStream = response.GetResponseStream();
int l;
do
{
l = inStream.Read(buffer, 0, buffer.Length);
if (l > 0)
outStream.Write(buffer, 0, l);
}
while (l > 0);
outStream.Close();
inStream.Close();
}
catch
{
Value = false;
}
return Value;
}
开发者ID:mzry1992,项目名称:workspace,代码行数:30,代码来源:GetSource.cs
示例16: ParseResponse
public ICommandResponse ParseResponse(WebResponse response)
{
return new SetObjectACLResponse
{
Policy = response.Headers["x-emc-policy"]
};
}
开发者ID:stephengodbold,项目名称:ninefold-dotnet-api,代码行数:7,代码来源:SetObjectACL.cs
示例17: PrintErrorResponse
/// <summary>Print the error message as it came from the server.</summary>
private void PrintErrorResponse(WebResponse response)
{
if (response == null)
{
return;
}
Stream responseStream = response.GetResponseStream();
try
{
Stream errorStream = Console.OpenStandardError();
try
{
Copy(responseStream, errorStream);
}
finally
{
errorStream.Close();
}
}
finally
{
responseStream.Close();
}
}
开发者ID:nagyist,项目名称:GoogleAnalytics-MonoMac-Demo,代码行数:26,代码来源:customertool.cs
示例18: getEncoding
/// <summary>
///
/// </summary>
/// <param name="response"></param>
/// <returns></returns>
private static Encoding getEncoding(WebResponse response)
{
try
{
String contentType = response.ContentType;
if (contentType == null)
{
return _encoding;
}
String[] strArray = contentType.ToLower(CultureInfo.InvariantCulture).Split(new char[] { ';', '=', ' ' });
Boolean isFind = false;
foreach (String item in strArray)
{
if (item == "charset")
{
isFind = true;
}
else if (isFind)
{
return Encoding.GetEncoding(item);
}
}
}
catch (Exception exception)
{
if (((exception is ThreadAbortException) || (exception is StackOverflowException)) || (exception is OutOfMemoryException))
{
throw;
}
}
return _encoding;
}
开发者ID:bookxiao,项目名称:orisoft,代码行数:37,代码来源:PageLoader.cs
示例19: ExtractJsonResponse
private static string ExtractJsonResponse(WebResponse response)
{
GetRateLimits(response);
var responseStream = response.GetResponseStream();
if (responseStream == null)
{
throw new StackExchangeException("Response stream is empty, unable to continue");
}
string json;
using (var outStream = new MemoryStream())
{
using (var zipStream = new GZipStream(responseStream, CompressionMode.Decompress))
{
zipStream.CopyTo(outStream);
outStream.Seek(0, SeekOrigin.Begin);
using (var reader = new StreamReader(outStream, Encoding.UTF8))
{
json = reader.ReadToEnd();
}
}
}
return json;
}
开发者ID:Paul-Hadfield,项目名称:MyWebSite,代码行数:26,代码来源:ApiV21Proxy.cs
示例20: HandleUnauthorizedResponse
private Action<HttpWebRequest> HandleUnauthorizedResponse(RavenConnectionStringOptions options, WebResponse webResponse)
{
if (options.ApiKey == null)
return null;
var oauthSource = webResponse.Headers["OAuth-Source"];
var useBasicAuthenticator =
string.IsNullOrEmpty(oauthSource) == false &&
oauthSource.EndsWith("/OAuth/API-Key", StringComparison.CurrentCultureIgnoreCase) == false;
if (string.IsNullOrEmpty(oauthSource))
oauthSource = options.Url + "/OAuth/API-Key";
var authenticator = authenticators.GetOrAdd(
GetCacheKey(options),
_ =>
{
if (useBasicAuthenticator)
{
return new BasicAuthenticator(enableBasicAuthenticationOverUnsecuredHttp: false);
}
return new SecuredAuthenticator();
});
return authenticator.DoOAuthRequest(oauthSource, options.ApiKey);
}
开发者ID:cocytus,项目名称:ravendb,代码行数:28,代码来源:HttpRavenRequestFactory.cs
注:本文中的System.Net.WebResponse类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论