gpt4 book ai didi

c# - 从另一个站点重定向流时出现 502 错误

转载 作者:太空狗 更新时间:2023-10-29 23:20:12 25 4
gpt4 key购买 nike

在我的 WEB Api 2 Controller 中,我想从一个站点请求文件并从我的 Controller 返回该文件。这是代码

public HttpResponseMessage GetLecture()
{
HttpWebRequest request = WebRequest.CreateHttp("http://openmedia.yale.edu/cgi-bin/open_yale/media_downloader.cgi?file=/courses/spring11/phil181/mp3/phil181_01_011111.mp3");
request.Referer = @"http://oyc.yale.edu/courses/";

var receivedResponse = request.GetResponse();

HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.OK);
response.Content = new StreamContent(receivedResponse.GetResponseStream());
response.Content.Headers.ContentType = MediaTypeHeaderValue.Parse(receivedResponse.ContentType);
response.Content.Headers.ContentDisposition = new ContentDispositionHeaderValue("attachment");
response.Content.Headers.ContentDisposition.FileName = "phil181_01_011111.mp3";
response.Content.Headers.ContentLength = receivedResponse.ContentLength;

return response;
}

在本地它工作正常,我可以下载该文件,但当我将其部署到 Azure 时,我收到 502 错误。 Web 服务器在充当网关或代理服务器时收到无效响应。

enter image description here

日志显示返回响应后失败,因此方法执行期间没有异常。

文件大小约为 50MB。对于较小的文件,代码可以正常工作。

如何让此代码在 Azure 上运行 50 MB 文件?

最佳答案

首先,我会推荐configuring remote IIS administration对于您的 Azure Web App,因为这将允许您直接访问 IIS 日志和相关设置。我强烈感觉该问题与 IIS/ASP.NET 限制有关。您已经指出该方法在几秒钟内完成执行,因此这可能不是超时问题。

您还提到该代码适用于较小的文件大小,但在大小增加时会失败。这指向IIS bufferingLimit将您的网站设置为一个较小的值(或者可能是 ~4 MB 的默认值)。 Here是一个链接,描述如何将此限制增加到所需值。希望这对你有用。如果没有,我建议深入研究您网站的 IIS 日志。

关于c# - 从另一个站点重定向流时出现 502 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47431807/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com