Downloading a file from a REST APIs which has serveral 302 Found giving issue in C# but done well in Postman and browserHow can I get System.Net.Http.HttpClient to not follow 302 redirects?How to download a file from a URL in C#?Issue downloading file with safari browserRESTful API Server in C#ASP.NET file download from serverDownload file from an ASP.NET Web API method using AngularJSNot able to download file using C# from a web api which works using postmanC# & XAML - Display JSON in ListView from Wunderground APIC# REST API Call - Working in Postman, NOT in CodeREST API: Download files from the front end on the backend serverC# socket download file from REST API

Random point on a sphere

My research paper filed as a patent in China by my Chinese supervisor without me as inventor

A shy person in a queue

In Germany, how can I maximize the impact of my charitable donations?

What is this unknown executable on my boot volume? Is it Malicious?

Make 1998 using the least possible digits 8

Why isn't `typename` required for a base class that is a nested type?

How can I fix a framing mistake so I can drywall?

Why does Coq include let-expressions in its core language

What officially disallows US presidents from driving?

What does 1500万0000円 mean on a price display?

What are uses of the byte after BRK instruction on 6502?

Parallel resistance in electric circuits

What does a Light weapon mean mechanically?

Where can I get an anonymous Rav Kav card issued?

How are aircraft depainted?

Is there a reliable way to hide/convey a message in vocal expressions (speech, song,...)

How is Team Scooby Doo (Mystery Inc.) funded?

Is low emotional intelligence associated with right-wing and prejudiced attitudes?

How to say "quirky" in German without sounding derogatory?

Modify width of first column in file with a variable number of fields, using awk

Telling my mother that I have anorexia without panicking her

Where can I find vomiting people?

Why did they ever make smaller than full-frame sensors?



Downloading a file from a REST APIs which has serveral 302 Found giving issue in C# but done well in Postman and browser


How can I get System.Net.Http.HttpClient to not follow 302 redirects?How to download a file from a URL in C#?Issue downloading file with safari browserRESTful API Server in C#ASP.NET file download from serverDownload file from an ASP.NET Web API method using AngularJSNot able to download file using C# from a web api which works using postmanC# & XAML - Display JSON in ListView from Wunderground APIC# REST API Call - Working in Postman, NOT in CodeREST API: Download files from the front end on the backend serverC# socket download file from REST API






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have called a Blackboard Learn APIs to download a file. The Url is




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download




When I click on the link on the browser I saw that there are 2 more 302 Found before getting content rendered on the browser.




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download
Status code: 302



https://blackboard.ddns.net/bbcswebdav/xid-1407_1?VxJw3wfC56=1553768183&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=LhqjIQu9ReJ6IaoXzfPALpMer7momaz%2BwYxyWPG3YFY%3D
Status code: 302



https://blackboard.ddns.net/bbcswebdav/courses/1001/Blackboard%20code.txt?VxJw3wfC56=1553767343&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=uSziSDgibsV8PoWygH4spxpX7lOdDGwAvtlIHvrbPxM%3D
Status code: 200




I tried on the Postman by sending Bearer token and request a GET request to call the method and it also received the content.



I have to write C# code to receive the content of the file but I don't receive file but receive 500 InternalServerError. I have been trying to fix the issue but no luck. Do you have any thoughts on this? Please help.



My code in C# console application is as below:



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download
string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

using (HttpClient client = new HttpClient())

client.BaseAddress = new Uri("https://blackboard.ddns.net/");
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;
HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.IsSuccessStatusCode)

result = response.Content.ReadAsByteArrayAsync().Result;





After reading a post How can I get System.Net.Http.HttpClient to not follow 302 redirects?, I tried to follow the 302 redirections and change the code as below but got the same 500 InternalServerError at the end.



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download

string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

HttpClientHandler clientHander = new HttpClientHandler();
clientHander.AllowAutoRedirect = false;

using (HttpClient client = new HttpClient(clientHander))

client.BaseAddress = new Uri("https://blackboard.ddns.net/");

client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;

HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.StatusCode == System.Net.HttpStatusCode.Found)

var locaton = response.Headers.Location.AbsoluteUri;
HttpResponseMessage secondResponse = client.GetAsync(locaton).Result;
if (secondResponse.StatusCode == System.Net.HttpStatusCode.Found)

string finalUrl = secondResponse.Headers.Location.OriginalString;
HttpResponseMessage thirdResponse = client.GetAsync(finalUrl).Result;
result = thirdResponse.Content.ReadAsByteArrayAsync().Result;
Console.Write(Encoding.UTF8.GetString(result));













share|improve this question


























  • The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

    – jdweng
    Mar 28 at 10:23

















0















I have called a Blackboard Learn APIs to download a file. The Url is




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download




When I click on the link on the browser I saw that there are 2 more 302 Found before getting content rendered on the browser.




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download
Status code: 302



https://blackboard.ddns.net/bbcswebdav/xid-1407_1?VxJw3wfC56=1553768183&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=LhqjIQu9ReJ6IaoXzfPALpMer7momaz%2BwYxyWPG3YFY%3D
Status code: 302



https://blackboard.ddns.net/bbcswebdav/courses/1001/Blackboard%20code.txt?VxJw3wfC56=1553767343&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=uSziSDgibsV8PoWygH4spxpX7lOdDGwAvtlIHvrbPxM%3D
Status code: 200




I tried on the Postman by sending Bearer token and request a GET request to call the method and it also received the content.



I have to write C# code to receive the content of the file but I don't receive file but receive 500 InternalServerError. I have been trying to fix the issue but no luck. Do you have any thoughts on this? Please help.



My code in C# console application is as below:



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download
string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

using (HttpClient client = new HttpClient())

client.BaseAddress = new Uri("https://blackboard.ddns.net/");
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;
HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.IsSuccessStatusCode)

result = response.Content.ReadAsByteArrayAsync().Result;





After reading a post How can I get System.Net.Http.HttpClient to not follow 302 redirects?, I tried to follow the 302 redirections and change the code as below but got the same 500 InternalServerError at the end.



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download

string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

HttpClientHandler clientHander = new HttpClientHandler();
clientHander.AllowAutoRedirect = false;

using (HttpClient client = new HttpClient(clientHander))

client.BaseAddress = new Uri("https://blackboard.ddns.net/");

client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;

HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.StatusCode == System.Net.HttpStatusCode.Found)

var locaton = response.Headers.Location.AbsoluteUri;
HttpResponseMessage secondResponse = client.GetAsync(locaton).Result;
if (secondResponse.StatusCode == System.Net.HttpStatusCode.Found)

string finalUrl = secondResponse.Headers.Location.OriginalString;
HttpResponseMessage thirdResponse = client.GetAsync(finalUrl).Result;
result = thirdResponse.Content.ReadAsByteArrayAsync().Result;
Console.Write(Encoding.UTF8.GetString(result));













share|improve this question


























  • The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

    – jdweng
    Mar 28 at 10:23













0












0








0








I have called a Blackboard Learn APIs to download a file. The Url is




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download




When I click on the link on the browser I saw that there are 2 more 302 Found before getting content rendered on the browser.




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download
Status code: 302



https://blackboard.ddns.net/bbcswebdav/xid-1407_1?VxJw3wfC56=1553768183&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=LhqjIQu9ReJ6IaoXzfPALpMer7momaz%2BwYxyWPG3YFY%3D
Status code: 302



https://blackboard.ddns.net/bbcswebdav/courses/1001/Blackboard%20code.txt?VxJw3wfC56=1553767343&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=uSziSDgibsV8PoWygH4spxpX7lOdDGwAvtlIHvrbPxM%3D
Status code: 200




I tried on the Postman by sending Bearer token and request a GET request to call the method and it also received the content.



I have to write C# code to receive the content of the file but I don't receive file but receive 500 InternalServerError. I have been trying to fix the issue but no luck. Do you have any thoughts on this? Please help.



My code in C# console application is as below:



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download
string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

using (HttpClient client = new HttpClient())

client.BaseAddress = new Uri("https://blackboard.ddns.net/");
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;
HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.IsSuccessStatusCode)

result = response.Content.ReadAsByteArrayAsync().Result;





After reading a post How can I get System.Net.Http.HttpClient to not follow 302 redirects?, I tried to follow the 302 redirections and change the code as below but got the same 500 InternalServerError at the end.



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download

string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

HttpClientHandler clientHander = new HttpClientHandler();
clientHander.AllowAutoRedirect = false;

using (HttpClient client = new HttpClient(clientHander))

client.BaseAddress = new Uri("https://blackboard.ddns.net/");

client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;

HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.StatusCode == System.Net.HttpStatusCode.Found)

var locaton = response.Headers.Location.AbsoluteUri;
HttpResponseMessage secondResponse = client.GetAsync(locaton).Result;
if (secondResponse.StatusCode == System.Net.HttpStatusCode.Found)

string finalUrl = secondResponse.Headers.Location.OriginalString;
HttpResponseMessage thirdResponse = client.GetAsync(finalUrl).Result;
result = thirdResponse.Content.ReadAsByteArrayAsync().Result;
Console.Write(Encoding.UTF8.GetString(result));













share|improve this question
















I have called a Blackboard Learn APIs to download a file. The Url is




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download




When I click on the link on the browser I saw that there are 2 more 302 Found before getting content rendered on the browser.




https://blackboard.ddns.net/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download
Status code: 302



https://blackboard.ddns.net/bbcswebdav/xid-1407_1?VxJw3wfC56=1553768183&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=LhqjIQu9ReJ6IaoXzfPALpMer7momaz%2BwYxyWPG3YFY%3D
Status code: 302



https://blackboard.ddns.net/bbcswebdav/courses/1001/Blackboard%20code.txt?VxJw3wfC56=1553767343&Kq3cZcYS15=6716bb2d5bc740c29eb11e01d75bc913&3cCnGYSz89=uSziSDgibsV8PoWygH4spxpX7lOdDGwAvtlIHvrbPxM%3D
Status code: 200




I tried on the Postman by sending Bearer token and request a GET request to call the method and it also received the content.



I have to write C# code to receive the content of the file but I don't receive file but receive 500 InternalServerError. I have been trying to fix the issue but no luck. Do you have any thoughts on this? Please help.



My code in C# console application is as below:



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download
string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

using (HttpClient client = new HttpClient())

client.BaseAddress = new Uri("https://blackboard.ddns.net/");
client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;
HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.IsSuccessStatusCode)

result = response.Content.ReadAsByteArrayAsync().Result;





After reading a post How can I get System.Net.Http.HttpClient to not follow 302 redirects?, I tried to follow the 302 redirections and change the code as below but got the same 500 InternalServerError at the end.



static void Main(string[] args)

//GET /learn/api/public/v1/courses/courseId/contents/contentId/attachments/attachmentId/download

string fileUrl = "/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download";

HttpClientHandler clientHander = new HttpClientHandler();
clientHander.AllowAutoRedirect = false;

using (HttpClient client = new HttpClient(clientHander))

client.BaseAddress = new Uri("https://blackboard.ddns.net/");

client.DefaultRequestHeaders.Authorization =
new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "avnPkfmWSnf2Y5aKf1497LahLD3eKuwn");

byte[] result = null;

HttpResponseMessage response = client.GetAsync(fileUrl).Result;

if (response.StatusCode == System.Net.HttpStatusCode.Found)

var locaton = response.Headers.Location.AbsoluteUri;
HttpResponseMessage secondResponse = client.GetAsync(locaton).Result;
if (secondResponse.StatusCode == System.Net.HttpStatusCode.Found)

string finalUrl = secondResponse.Headers.Location.OriginalString;
HttpResponseMessage thirdResponse = client.GetAsync(finalUrl).Result;
result = thirdResponse.Content.ReadAsByteArrayAsync().Result;
Console.Write(Encoding.UTF8.GetString(result));










c# http-status-code-302 blackboard






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 28 at 12:01







Simant

















asked Mar 28 at 10:06









SimantSimant

5984 silver badges22 bronze badges




5984 silver badges22 bronze badges















  • The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

    – jdweng
    Mar 28 at 10:23

















  • The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

    – jdweng
    Mar 28 at 10:23
















The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

– jdweng
Mar 28 at 10:23





The best way to fix problem is to use a sniffer like wireshark or fiddler. Compare working sniffer data with non working fiddler data. Look at the working request headers and make non working headers the same. There are too many reasons for failure to start guessing at the correct answer. Only way for sure is to use sniffer.

– jdweng
Mar 28 at 10:23












1 Answer
1






active

oldest

votes


















0
















I have tried with different HTTP clients available in .NET (HttpWebRequest/Response, WebClient, HttpClient), but always received 500 Internal Server Error. So, I decided to test with a third-party HTTP client and luckily RestSharp worked for me.



public ActionResult Index()

var client = new RestClient("https://blackboard.ddns.net/");

var request = new RestRequest("/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download", Method.GET);

client.AddDefaultHeader("Authorization", "Bearer ZVAFzAuZ1ujYRENLrjNv3b8UWWvgRic4");

var response = client.Execute(request);

return File(response.RawBytes, "text/plain", "MyTest.txt");







share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );














    draft saved

    draft discarded
















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394873%2fdownloading-a-file-from-a-rest-apis-which-has-serveral-302-found-giving-issue-in%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0
















    I have tried with different HTTP clients available in .NET (HttpWebRequest/Response, WebClient, HttpClient), but always received 500 Internal Server Error. So, I decided to test with a third-party HTTP client and luckily RestSharp worked for me.



    public ActionResult Index()

    var client = new RestClient("https://blackboard.ddns.net/");

    var request = new RestRequest("/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download", Method.GET);

    client.AddDefaultHeader("Authorization", "Bearer ZVAFzAuZ1ujYRENLrjNv3b8UWWvgRic4");

    var response = client.Execute(request);

    return File(response.RawBytes, "text/plain", "MyTest.txt");







    share|improve this answer





























      0
















      I have tried with different HTTP clients available in .NET (HttpWebRequest/Response, WebClient, HttpClient), but always received 500 Internal Server Error. So, I decided to test with a third-party HTTP client and luckily RestSharp worked for me.



      public ActionResult Index()

      var client = new RestClient("https://blackboard.ddns.net/");

      var request = new RestRequest("/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download", Method.GET);

      client.AddDefaultHeader("Authorization", "Bearer ZVAFzAuZ1ujYRENLrjNv3b8UWWvgRic4");

      var response = client.Execute(request);

      return File(response.RawBytes, "text/plain", "MyTest.txt");







      share|improve this answer



























        0














        0










        0









        I have tried with different HTTP clients available in .NET (HttpWebRequest/Response, WebClient, HttpClient), but always received 500 Internal Server Error. So, I decided to test with a third-party HTTP client and luckily RestSharp worked for me.



        public ActionResult Index()

        var client = new RestClient("https://blackboard.ddns.net/");

        var request = new RestRequest("/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download", Method.GET);

        client.AddDefaultHeader("Authorization", "Bearer ZVAFzAuZ1ujYRENLrjNv3b8UWWvgRic4");

        var response = client.Execute(request);

        return File(response.RawBytes, "text/plain", "MyTest.txt");







        share|improve this answer













        I have tried with different HTTP clients available in .NET (HttpWebRequest/Response, WebClient, HttpClient), but always received 500 Internal Server Error. So, I decided to test with a third-party HTTP client and luckily RestSharp worked for me.



        public ActionResult Index()

        var client = new RestClient("https://blackboard.ddns.net/");

        var request = new RestRequest("/learn/api/public/v1/courses/uuid:d23e128e62f8483699c26836e06cab32/contents/_27_1/attachments/_13_1/download", Method.GET);

        client.AddDefaultHeader("Authorization", "Bearer ZVAFzAuZ1ujYRENLrjNv3b8UWWvgRic4");

        var response = client.Execute(request);

        return File(response.RawBytes, "text/plain", "MyTest.txt");








        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Apr 1 at 11:50









        SimantSimant

        5984 silver badges22 bronze badges




        5984 silver badges22 bronze badges



















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.




















            draft saved

            draft discarded















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55394873%2fdownloading-a-file-from-a-rest-apis-which-has-serveral-302-found-giving-issue-in%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript