【发布时间】:2020-09-12 03:56:58
【问题描述】:
我在使用 Uno 平台的 WebAssembly 上遇到了这些错误。
从 'https://localhost:44318/api/search/bebek/TR' 获取的访问权限 来源“http://localhost:49917”已被 CORS 策略阻止:否 请求中存在“Access-Control-Allow-Origin”标头 资源。如果不透明的响应满足您的需求,请设置请求的 模式为“no-cors”以获取禁用 CORS 的资源。
我从 API 服务获得了一些 JSON 文件形式的数据响应。 UWP 应用执行此操作时不会出错:
//_savedSearchList = await _dbService.SearchAsync(_keyword, _sentLanguageArgument); // Normal database connection for UWP.
//_savedSearchList = await _dbService.SearchAsync(_keyword, _sentLanguageArgument); // Normal database connection for UWP.
//Get search list for webservice.
var link_search = $"https://localhost:44318/api/search/{_keyword.ToLower()}/{_sentLanguageArgument}";
using (HttpClient client = new HttpClient())
{
HttpResponseMessage response = await client.GetAsync(link_search);
Debug.WriteLine($"Http Status Code for Connection: {response.StatusCode}");
if (response.IsSuccessStatusCode)
{
var jsonString = await response.Content.ReadAsStringAsync();
_savedSearchList = JsonConvert.DeserializeObject<List<SearchResultCapsule>>(jsonString).OrderBy(t => t.IssueNumber);
if (_savedSearchList.Count() != 0)
{
ResultList.ItemsSource = _savedSearchList;
NoResult_Grid.Visibility = Visibility.Collapsed;
}
}
}
WebAssembly 的真正问题是什么?我该如何解决?谢谢。
【问题讨论】:
标签: asp.net-core .net-core uwp xmlhttprequest uno-platform