In my WEB Api 2 controller I want to request file from one site and return this file from my controller. Here is the code
public HttpResponseMessage GetLecture()
{
HttpWebRequest request = WebRequest.CreateHttp("http://ift.tt/2zsdJdK");
request.Referer = @"http://ift.tt/2mSsRuT";
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;
}
Locally it works fine and I can download the file but when I deploy it to Azure I'm getting 502 Error. Web server received an invalid response while acting as a gateway or proxy server.
Logging shows that it fails after returning response so no exceptions during method execution. All sorts of logs that Azure provides didn't give me any clues. What is wrong with that code?
Aucun commentaire:
Enregistrer un commentaire