本文整理汇总了C#中System.Net.Response.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# Response.AddHeader方法的具体用法?C# Response.AddHeader怎么用?C# Response.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Response
的用法示例。
在下文中一共展示了Response.AddHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: App
public static AppAction App()
{
return (env, fault, result) => {
var request = new Request(env);
var response = new Response(result);
if (string.IsNullOrWhiteSpace(request.GET["Url"])) {
response.ContentType = "text/html";
response
.Write("<form>")
.Write("Url <input type='text' name='Url' style='width:50%;' value='http://download.microsoft.com/download/f/e/6/fe6eb291-e187-4b06-ad78-bb45d066c30f/6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
.Write("Save as <input type='text' name='SaveAs' style='width:50%;' value='6.0.6001.18000.367-KRMSDK_EN.iso'/><br/>")
.Write("<input type='submit' value='Go'/>")
.Write("</form>")
.Finish();
}
else {
// make remote request asynchronously
var remoteRequest = WebRequest.Create(request.GET["Url"]);
remoteRequest.BeginGetResponse(getResponseResult => fault.Guard(() => {
var remoteResponse = (HttpWebResponse)remoteRequest.EndGetResponse(getResponseResult);
// pass some response headers along
response.Status = (int)remoteResponse.StatusCode;
response.ContentType = remoteResponse.ContentType;
if (!string.IsNullOrWhiteSpace(request.GET["SaveAs"])) {
response.AddHeader("Content-Disposition", "attachment; filename=" + request.GET["SaveAs"]);
}
// pass response body along
var remoteStream = remoteResponse.GetResponseStream();
if (remoteStream == null) {
response.Finish();
}
else {
var buffer = new byte[4096];
response.Finish((next, error, complete) =>
Loop.Run((halted, continuation) => error.Guard(() =>
remoteStream.BeginRead(buffer, 0, buffer.Length, streamResult => error.Guard(() => {
var count = remoteStream.EndRead(streamResult);
if (halted()) {
return;
}
if (count <= 0) {
complete();
return;
}
if (!next.InvokeAsync(new ArraySegment<byte>(buffer, 0, count), continuation)) {
continuation();
}
}), null))));
}
}), null);
}
};
}
示例2: Should_map_headers_from_original_response
public void Should_map_headers_from_original_response()
{
// given
var response = new Response();
response.AddHeader("cache-control", "no-cache");
var httpListenerResponse = CreateHttpListenerResponse();
// when
new HttpListenerResponseMapper().Map(response, httpListenerResponse);
// then
Check.That(httpListenerResponse.Headers).HasSize(1);
Check.That(httpListenerResponse.Headers.Keys).Contains("cache-control");
Check.That(httpListenerResponse.Headers.Get("cache-control")).Contains("no-cache");
}