0

customerLogin is object that I want to send to my service. I do not want to use query string and do not want parameters separately. Below is the code:

var config = {
  customerLogin : {  // object I intend to send
    'EmailID': $scope.existingCustomer.email,
    'PhoneNumber': $scope.existingCustomer.phoneNumber,
    'Passkey': $scope.existingCustomer.password
  }
}
$http.get(existingCustomerUrlConstant, config).

In webapi, i have below code:

 [HttpGet]
 // customerLogin object i want to receive here
 public CustomerLogin GetCustomer(CustomerLogin customerLogin)
 {
     GetCustomerDAL getCustomerDAL = new GetCustomerDAL(customerLogin);
     return customerLogin;
 }

customerLogin is null here. How can i receive object here from Angular service call?

3
  • 3
    Are you sure you dont want to user POST method instead? Commented Jul 30, 2016 at 18:45
  • If you want to send additional data with an HTTP GET you must use the query string or something in the URL itself. That's just the way that GET works. If you don't want any data in the URL, then you have to use POST, PATCH, PUT, etc... Commented Jul 30, 2016 at 18:47
  • @ZdenekHatak: Since I was getting the data, I thought of using GET. With POST, it works fine. I thought it would be good practice. Commented Jul 30, 2016 at 18:51

1 Answer 1

1

Using POST method is the right call. As I stated in the comment.

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

2 Comments

I have a question. If I need to use POST when I need to send object, then when would I use http.get, http.delete, http.put etc? Let me know here or share a link. Please.
$HTTP.GET is for generally for simple getting stuff from an URL. DELETE for deleting stuff - e.g, in frontend of admin you send $http.delete to delete an article and the backend has to listen to the delete method and process the delete in the database. PUT is for updating things. Read more about REST.

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.