Reputation: 104
Do you know why this is not working on Blazor WebAssembly ?
[Inject]
public HttpClient Http { get; set; }
public string Feeds { get; set; }
protected async override Task OnInitializedAsync()
{
var request = new HttpRequestMessage(HttpMethod.Get, "https://hassanhabib.com/feed/");
request.SetBrowserRequestMode(BrowserRequestMode.NoCors);
using var httpResponse = await Http.SendAsync(request);
Feeds = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);
}
the httpResponse.StatusCode
is all time 0. 😒
If you do this on Sever Side it works ... or in .NET Framework app.
Thanks
Upvotes: 0
Views: 650
Reputation: 17532
It looks like what you are seeing here is an "opaque" response as defined in the fetch specification.
An opaque filtered response is a filtered response whose type is "opaque", URL list is the empty list, status is 0, status message is the empty byte sequence, header list is empty, and body is null.
There is no way around this on the browser side, the only way it will work is if the source adds the correct CORS headers to whitelist your origin.
More information can be found here: https://stackoverflow.com/a/54906434/547640
Upvotes: 1