Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
62 views
in Technique[技术] by (71.8m points)

Sending HttpRequest from Blazor WebAsembly

I have the following code to try sending a Http request to my test server:

var request = new HttpRequestMessage(HttpMethod.Get, "http://localhost:5000/api/Logon");
request.Headers.Add("testheader", "1234");
var httpResponse = await Http.SendAsync(request);

But if I use Fiddler to see what is actual sent I get this in the Headers:

OPTIONS http://localhost:5000/api/Logon HTTP/1.1
Host: localhost:5000
Connection: keep-alive
Accept: */*
Access-Control-Request-Method: GET
Access-Control-Request-Headers: testheader
Origin: http://localhost:5005
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.104 Safari/537.36
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
Sec-Fetch-Dest: empty
Referer: http://localhost:5005/
Accept-Encoding: gzip, deflate, br
Accept-Language: en-GB,en-US;q=0.9,en;q=0.8

Why is it adding my custom header of 'testheader' to the Access-Control-Request-Headers?

question from:https://stackoverflow.com/questions/65919505/sending-httprequest-from-blazor-webasembly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It turns out this was down to running my blazor client through VS2019 and IISExpress.

I had to add the Access-Control-Request-Headers to the IISExpress custom headers config file.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...