0

There must be something wrong with my c# code. I am trying to download some Json from an Azure Blob. I can download the Json in Postman and from MS Edge however, using my code there are no apparent errors in the request but there is no content in the response. Presumably there is something wrong with my code.

    async Task GetJson()
    {
        var request = new HttpRequestMessage
        {
            Method = new HttpMethod("GET"),
            RequestUri = new Uri("https://xxx.blob.core.windows.net/trading/m5.json")
        };
        request.Headers.Add("Accept", "application/json");
        request.SetBrowserRequestMode(BrowserRequestMode.NoCors);

        var response = await http.SendAsync(request);
        var json = await response.Content.ReadAsStringAsync();

    
    }
Paul Stanley
  • 1,999
  • 1
  • 22
  • 60

1 Answers1

1

This was asked on GitHub and apparently it is by design.

When you remove request.SetBrowserRequestMode(BrowserRequestMode.NoCors); line you will see the No 'Access-Control-Allow-Origin' header is present error.

Specifiying BrowserRequestMode.NoCors does not let you bypass the Browser security rules. It just simplifies the request headers.

H H
  • 263,252
  • 30
  • 330
  • 514