2016-07-30 64 views
0

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

回答

1

使用POST方法是正確的調用。正如我在評論中所述。

+0

我有一個問題。如果我需要發送對象時需要使用POST,那麼何時使用http.get,http.delete,http.put等?讓我知道這裏或分享鏈接。請。 – Amit

+0

$ HTTP.GET通常用於簡單從URL中獲取內容。 DELETE刪除東西 - 例如,在管理員的前端,您發送$ http.delete刪除文章,後端必須收聽刪除方法並處理數據庫中的刪除。 PUT用於更新事物。閱讀更多關於REST的信息。 –