本文整理汇总了C#中System.Net.WebResponse类的典型用法代码示例。如果您正苦于以下问题:C# WebResponse类的具体用法?C# WebResponse怎么用?C# WebResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebResponse类属于System.Net命名空间,在下文中一共展示了WebResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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;
}
示例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()
});
}
}
}
}
示例4: ExtendedHttpWebResponse
public ExtendedHttpWebResponse(Uri responseUri, WebResponse response, Stream responseStream, CacheInfo cacheInfo)
{
this.responseUri = responseUri;
this.response = response;
this.responseStream = responseStream;
this.cacheInfo = cacheInfo;
}
示例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;
}
示例6: FromResponse
public static dynamic FromResponse(WebResponse response)
{
using (var stream = response.GetResponseStream())
{
return FromStream(stream);
}
}
示例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;
}
示例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;
}
示例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;
}
}
示例10: SharpBoxException
internal SharpBoxException(SharpBoxErrorCodes errorCode, Exception innerException, WebRequest request, WebResponse response)
: base(GetErrorMessage(errorCode), innerException)
{
ErrorCode = errorCode;
PostedRequet = request;
DisposedReceivedResponse = response;
}
示例11: WebException
public WebException(String msg, Exception inner,
WebExceptionStatus status, WebResponse response)
: base(msg, inner)
{
myresponse = response;
mystatus = status;
}
示例12: ReadAll
private string ReadAll(WebResponse webResponse)
{
using (var reader = new StreamReader(webResponse.GetResponseStream()))
{
return reader.ReadToEnd();
}
}
示例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;
}
示例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);
}
}
示例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;
}