2016-01-06 73 views
1

問題如下:

我想使用get與body來使用RESTful服務。出於測試目的,我使用Fiddler Web Debugger。

現在,下面的GET請求投入提琴手得到我的結果,我期待:

GET http://localhost:3787/TerminologyService/Autosuggest/ HTTP/1.1 
Host: localhost:3787 
Content-Length: 215 
Content-Type: application/json 

{ 
"Text": "war", 
"Count": "100", 
"MedicationWeight": "7", 
"ActivityWeight": "0", 
"DiseaseWeight": "0", 
"GeneWeight": "0", 
"SymptomWeight": "0", 
"AnatomyWeight": "0", 
"OrderingType": "CATEGORY_DIVERSITY" 
} 

所以,現在我使用$ http.get做同樣的事情。 這裏是我到目前爲止有:

function getTerms(text, count, medWeight, actWeight, disWeight, genWeight, symWeight, anaWeight, orderingType) 
    { 
     var config = { 
      headers: {'Content-Type' : 'application/json'}, 
      params: {Text : text, 
          Count : count, 
          MedicationWeight : medWeight, 
          ActivityWeight : actWeight, 
          DiseaseWeight : disWeight, 
          GeneWeight : genWeight, 
          SymptomWeight : symWeight, 
          AnatomyWeight : anaWeight, 
          OrderingType : orderingType} 
     } 

     return $http.get(
      'http://localhost:3787/TerminologyService/Autosuggest', config); 
    } 

這並獲得形成一個GET網址:

http://localhost:3787/TerminologyService/Autosuggest?ActivityWeight=0&AnatomyWeight=0&Count=10&DiseaseWeight=0&GeneWeight=0&MedicationWeight=7&OrderingType=CATEGORY_DIVERSITY&SymptomWeight=0&Text=war 

不幸的是,這會導致錯誤500的web服務。

當我檢查由$ http.get調用生成的Fiddler中捕獲的流量時,我發現JSON數據沒有作爲正文傳遞(顯然,因爲它是通過URL傳遞的)。所以我沒能得到什麼,我第一次在提琴手

任何幫助深表感謝

+0

500指在服務器上發生的錯誤side..you應調試代碼在服務器.. –

+0

是發生的原因是未如預期形成錯誤的請求通過web服務。我無法通過GET機構,因爲我在我的提琴手測試中。 –

+0

獲取請求確實只通過URL傳遞所有參數。 –

回答

1

更新:

問題是通過改變回到POST解決。

我錯誤地認爲我應該使用GET

0

你不應該在你的後端的GET請求來期待一個身體測試,但回答你的問題的緣故,如$http docs中所述,您可以將請求的正文消息傳遞給配置對象的data屬性。所以使用data而不是params,它應該有你想要的行爲。

+0

非常感謝您的回覆。我曾假設我應該使用GET,但那不是事實。所以我在後臺將它改回Post,現在它正在工作。 –