2

I get this error when I send Post. Do you know what I have to do? Login to WinApi C#

XMLHttpRequest cannot load http://localhost:56305/Token. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:64757' is therefore not allowed access. The response had HTTP status code 400.

My code

//linki
    $scope.addLink = "http://localhost:56305/Token";

    $scope.addData = function () {
        if ($scope.password != "" && $scope.email) {
            $http({
                method: "POST",
                url: $scope.addLink,
                headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
                headers: {'X-Requested-With' :'XMLHttpRequest'},
                data: { grant_type: 'password', username: $scope.email, Password: $scope.password }
            }).then(function mySucces(response) {
                $scope.stateHideError = true;
                $scope.stateHideSuccess = false;
                Authorization.go('carInsurance');
            }, function myError(response) {
                $scope.stateHideError = false;
                $scope.stateHideSuccess = true;
                $scope.error = "Wystąpił błąd - Problem z wysłaniem parametrów";
            });
        }
        else {
            $scope.stateHideError = false;
            $scope.stateHideSuccess = true;
            $scope.error = "Wystąpił błąd - nie podałeś wszystkich wymaganych wartości.";
        }
    };

PtrScn enter image description here

I would like send something like this

enter image description here

I added this to WinApi C#

    <httpProtocol>
        <customHeaders>
          <add name="Access-Control-Allow-Origin" value="*"/>
        </customHeaders>
    </httpProtocol>

and now I have this error

XMLHttpRequest cannot load http://localhost:56305/Token. Response for preflight has invalid HTTP status code 400

1 Answer 1

2

This is a sample article, how to enable CORS http://www.asp.net/web-api/overview/security/enabling-cross-origin-requests-in-web-api

Your server rejects requests from your js application,because your js is loaded from different URL

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.