【发布时间】:2015-01-13 15:00:44
【问题描述】:
我想通过代理脚本向我的后端服务器发送查询。但它不能正确返回文件。
public class HttpWebRequestRunner : IWebRequestRunner
{
public HttpWebResponse Run(string backendUri)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(backendUri);
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
return response;
}
}
我的后端服务器对互联网关闭,所以我向我的 Asp.Net Mvc 应用程序发送参数。并将请求发送到后端服务器。
后端服务器正在为此请求返回文件:http://10.0.2.1/Employee/CV/1445
在我的 mvc 控制器中我使用这个:
public class PersonController : Controller
{
public ActionResult GetCv(int id)
{
HttpWebResponse response = new HttpWebResponse();
HttpWebResponse webResponse = response.run("http://10.0.2.1/Employee/CV/1445");
context.HttpContext.Response.ContentType = wbResponse.ContentType;
webResponse.GetResponseStream().CopyTo(context.HttpContext.Response.OutputStream);
// write result...
}
}
现在
如果我从浏览器向后端发送请求,这个 url http://10.0.2.1/Employee/CV/1445 它会返回 1445.pdf 文件
但是如果我通过像这样的代理应用程序发送请求http://localhost:22414/Person/GetCv/1445
这将返回一个名为 file 但不是 pdf 扩展名的文件。
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
标签: c# asp.net asp.net-mvc httpwebrequest