我在C#中有一个返回
的异步任务Task<HttpResponseMessage>
代码如下
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.Moved);
response.Headers.Location = new Uri(new Shared().ToAbsoluteUrl("~/html/fail.aspx"));
return response;
在ASPX页面的代码隐藏中,我有以下代码
IRestResponse response = client.Execute(request);
if (response.Headers.Any(t => t.Name == "Location"))
{
string location = response.Headers.FirstOrDefault(t => t.Name == "Location").Value.ToString();
}
问题:我无法在代码隐藏中检索位置标头值。有任何想法吗?
答案 0 :(得分:0)
添加以下内容:
client.FollowRedirects = false;
在此之前:
IRestResponse response = client.Execute(request);