Call Web Api 2.0 C# from Meteor

#1

Hi,
I have created a example of project app device from meteor.
Inside my code I created side server have created a CRUD with C # web api 2.0.
While meteor side I created on method inside main.js on the SERVER folder, where I’m going to point to the web api:


    addStudent:function(FirstName,LastName,Email,Address){ 
       Toast.info(result);
        this.unblock();
        var result = Meteor.http.call("POST","",
                       {
                        data:{
                                "FirstName": FirstName,
                                "LastName" : LastName,
                                "Email": Email,
                                "Address":Address
                            }
                        }
                    );
            //Toast.info(result);
        return result;
    },`

and inside main.js I called the method in the client:

Template.createStudent.events({

		'click #btnCreate':function(events){			
			events.preventDefault();
			var Firstname='pippo';
			var Lastname='pluto';
			var Email='tizio1@libero.it';
			var Address='via polo nord';
			setTimeout(function() {	
				Meteor.call("addStudent",Firstname,Lastname,Email,Address, function(error, result) {
					
				    if (error) {
				    	Toast.info("Client:" + error);
				        alert("Oops!!! Something went wrong!");
				    } 
				    else {
				    	Toast.info("Client:" + result);
						Session.set('tx', result);
				    }    
				});	  
			});
		}
	});

When I go to throw (“meteor run Android-device”) the project concerned, and connect the usb of my phone, he does not call the service, but if I run it on the browser (“localhost: 3000”), everything works fine.

Could you help me understand why?

Thank you

#2

You probably forgot to enable CORS on your API.

#3

Hello,
I added the enablecors server side, but still does not work.

What am I doing wrong?