小编Bha*_*kar的帖子

如何在 asp.net 自托管 API 中启用 CORS?

我在 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)

c# asp.net cors self-host-webapi

5
推荐指数
1
解决办法
1360
查看次数

如何使用Stream拆分集合中的奇数和偶数以及两者的总和

我如何使用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)

java collections lambda java-8 java-stream

1
推荐指数
2
解决办法
6774
查看次数

标签 统计

asp.net ×1

c# ×1

collections ×1

cors ×1

java ×1

java-8 ×1

java-stream ×1

lambda ×1

self-host-webapi ×1