我有一个网络api(但从Controller继承)和一个Post Action来上传一些文件。 有没有简单的方法可以将请求“重定向”到另一台服务器?现在,我正在创建另一个http请求
[HttpPost]
public async Task<ActionResult> Upload(IList<HttpPostedFileBase> files)
{
// if true
// HERE: send this request to another server on simple way
// right now
if (true)
Redirect("myURL", files);
// other logics to return result here
else
//my save file logic here
}
async Task<HttpResponseMessage> Redirect(string url, IList<HttpPostedFileBase> files)
{
using (var http = new HttpClient())
{
http.Timeout = new TimeSpan(0, 60, 0);
using (var content = new MultipartFormDataContent())
{
foreach (var file in files)
content.Add(Http.CreateFileContent(file.InputStream, file.FileName, file.ContentType));
return await http.PostAsync(url, content);
}
}
}