简体   繁体   中英

Blazor WASM : httpResponse.StatusCode all time 0

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

It looks like what you are seeing here is an "opaque" response as defined in thefetch 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM