0

Hope some one can help me here.

I am trying to POST a JOSN data to restful service. But am getting below error.

Error:

XMLHttpRequest cannot load http://localhost:8080/PortalService/rest/PutService/PutLogicalTeam. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:63342' is therefore not allowed access.

This is how i am invoking the service

$http.post('http://localhost:8080/PortalService/rest/PutService/PutLogicalTeam', $scope.strLogiTeam
        ).success(function(data, status, headers, config) {

                console.log("success");
            }).error(function(data, status, headers, config) {
                // Handle error
                console.log(status);
            });

My service.

I am not even trying to pull the data. I am just trying to check whether my service is getting invoked or not.

@POST
    @Consumes("application/json")
    @Path("/PutLogicalTeam")
    public void putNewLogicalTeam(LogicalTeam newLogicalTeam)
    {
        System.out.println("Invoked");
    }

I also tried like below

$http({
            method: 'POST',
            dataType: 'jsonp',
            data: $scope.strLogiTeam,
            url:'http://localhost:8080/PortalService/rest/PutService/PutLogicalTeam',
            headers: {'Content-Type':'application/json'}
        });

Can some one review and help. Also suggest the better way to use the web service

Vinoth Sivakumar
  • 55
  • 1
  • 2
  • 9
  • If on a terminal you try to do `curl http://localhost:8080/PortalService/rest/PutService/PutLogicalTeam` from CLI what's the reply? I want to understand if it's a [CORS](https://en.wikipedia.org/wiki/Cross-origin_resource_sharing) problem or a backend problem – rpadovani Apr 10 '15 at 11:13
  • Error is quite clear. CORS enable the web service or set it up on same domain and port – charlietfl Apr 10 '15 at 11:13
  • possible duplicate of [XMLHttpRequest cannot load, No 'Access-Control-Allow-Origin' header is present on the requested resource.](http://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin?rq=1) – Ramesh Rajendran Apr 10 '15 at 11:37

0 Answers0