Angular:如何通过$ http.get发送对象?

Angular:如何通过$ http.get发送对象?

问题描述:

customerLogin是我想要发送给我的服务的对象。 我不想使用查询字符串,也不想单独分开参数。 下面是代码:

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

在的WebAPI,我有下面的代码:

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

customerLogin为空在这里。 如何从角度服务呼叫接收对象?

+3

你确定你不想用POST方法吗? –

+0

如果你想通过'HTTP GET'发送额外的数据,你必须使用查询字符串或URL本身。这就是GET的工作方式。如果你不想在URL中有任何数据,那么你必须使用POST,PATCH,PUT等等...... –

+0

@ZdenekHatak:自从我获取数据后,我想到了使用GET。用POST,它工作正常。我认为这将是一个好习惯。 – Amit

使用POST方法是正确的调用。正如我在评论中所述。

+0

我有一个问题。如果我需要发送对象时需要使用POST,那么何时使用http.get,http.delete,http.put等?让我知道这里或分享链接。请。 – Amit

+0

$ HTTP.GET通常用于简单从URL中获取内容。 DELETE删除东西 - 例如,在管理员的前端,您发送$ http.delete删除文章,后端必须收听删除方法并处理数据库中的删除。 PUT用于更新事物。阅读更多关于REST的信息。 –