Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带有WebAPI的AngularJS将JSON参数传递给$http.get_Angularjs_Json_Asp.net Web Api_Get - Fatal编程技术网

带有WebAPI的AngularJS将JSON参数传递给$http.get

带有WebAPI的AngularJS将JSON参数传递给$http.get,angularjs,json,asp.net-web-api,get,Angularjs,Json,Asp.net Web Api,Get,问题如下: 我想使用带有主体的get来使用RESTful服务。出于测试目的,我使用Fiddler Web调试器 现在,下面的GET请求放入Fiddler,得到了我期望的结果: GET http://localhost:3787/TerminologyService/Autosuggest/ HTTP/1.1 Host: localhost:3787 Content-Length: 215 Content-Type: application/json { "Text": "war", "Cou

问题如下:

我想使用带有主体的get来使用RESTful服务。出于测试目的,我使用Fiddler Web调试器

现在,下面的GET请求放入Fiddler,得到了我期望的结果:

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 url:

http://localhost:3787/TerminologyService/Autosuggest?ActivityWeight=0&AnatomyWeight=0&Count=10&DiseaseWeight=0&GeneWeight=0&MedicationWeight=7&OrderingType=CATEGORY_DIVERSITY&SymptomWeight=0&Text=war
不幸的是,这会导致webservice出现错误500

当我检查由$http.get调用生成的Fiddler中捕获的流量时,我发现JSON数据没有作为主体传递(显然,因为它是在URL中传递的)。所以我无法得到我在Fiddler中第一次测试的结果


非常感谢您提供的任何帮助

您不应该期望在后端的GET请求中包含正文,但为了回答您的问题,如中所述,您可以将请求的正文消息传递给config object的
数据
属性。因此,使用
数据
而不是
参数
,它应该具有您想要的行为。

更新:

通过更改“返回岗位”解决了此问题


我错误地认为我应该使用GET

500表示错误发生在服务器端。您应该通过服务器调试代码。是的,出现错误是因为请求的格式与Web服务的预期不符。我无法通过GET正文,因为我正在进行Fiddler测试。GET请求只通过URL传递所有参数。查看Fiddler中我的OP顶部的GET请求,可以看出URL没有附加任何内容,但我得到了预期的结果。非常感谢您的回复。我本以为我应该使用GET,但事实并非如此。所以我把它改回后端的Post,现在它开始工作了。