我在 asp.net 中创建了一个自托管的 Web API,当我从 POSTMAN 调用它时它工作正常,但是当我从浏览器调用它时出现以下错误。
从源 ' http://localhost:4200 '访问 XMLHttpRequest at ' http://localhost:3273/Values/GetString/1 '已被 CORS 策略阻止:No 'Access-Control-A
下面给出的是我的服务类
using System.Web.Http;
using System.Web.Http.SelfHost;
namespace SFLSolidWorkAPI
{
public partial class SolidWorkService : ServiceBase
{
public SolidWorkService()
{
InitializeComponent();
}
protected override void OnStart(string[] args)
{
var config = new HttpSelfHostConfiguration("http://localhost:8069");
config.Routes.MapHttpRoute(
name: "API",
routeTemplate: "{controller}/{action}/{id}",
defaults: new { id = RouteParameter.Optional }
);
HttpSelfHostServer server = new HttpSelfHostServer(config);
server.OpenAsync().Wait();
}
protected override void OnStop()
{
}
}
}
Run Code Online (Sandbox Code Playgroud) 我如何使用java-8的Stream方法拆分奇数和偶数并在集合中求和?
public class SplitAndSumOddEven {
public static void main(String[] args) {
// Read the input
try (Scanner scanner = new Scanner(System.in)) {
// Read the number of inputs needs to read.
int length = scanner.nextInt();
// Fillup the list of inputs
List<Integer> inputList = new ArrayList<>();
for (int i = 0; i < length; i++) {
inputList.add(scanner.nextInt());
}
// TODO:: operate on inputs and produce output as output map
Map<Boolean, Integer> oddAndEvenSums = inputList.stream(); \\here I want to split odd …Run Code Online (Sandbox Code Playgroud)