Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/32.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
Angular 角度http获取发送主体参数作为请求中的json_Angular_Httpclient - Fatal编程技术网

Angular 角度http获取发送主体参数作为请求中的json

Angular 角度http获取发送主体参数作为请求中的json,angular,httpclient,Angular,Httpclient,我正试图提出这个要求: curl --location --request GET 'http://localhost:5000/location/searchDistanceAndTags?pageNo=1&size=1' \ --header 'token: $IKFASOmV#*+JIL4X0FGTDZNRPB3GN7HvAB9QD2X8QWeLsqtKW1U5YHnxCMRywEbUZlu??oz!!!!6r' \ --header 'Content-Type: applicat

我正试图提出这个要求:

curl --location --request GET 'http://localhost:5000/location/searchDistanceAndTags?pageNo=1&size=1' \
--header 'token: $IKFASOmV#*+JIL4X0FGTDZNRPB3GN7HvAB9QD2X8QWeLsqtKW1U5YHnxCMRywEbUZlu??oz!!!!6r' \
--header 'Content-Type: application/json' \
--data-raw '{
"lat": "38.8993487",
"lng": "-77.0145665",
"radius": "100",
"tags": ["bier"]
}'
这是我的angular代码,不幸的是没有设置参数(后端没有在req.body中接收任何数据)

const数据集={
lat:'38.8993487',
液化天然气:'-77.0145665',
半径:“100”,
标签:['bier']
};
返回此。\u httpClient.get(`http://localhost:5000/location/searchDistanceAndTags?pageNo=${this.pageNumber}&size=10`{
标头:{token:this.apikey,
'内容类型':'应用程序/json'},
参数:数据集
});

可以通过HttpParams发送参数:

const params = new HttpParams()
   .set('lat', 'one!')
   .set('lng', "two");  // and so on
可以通过以下方式创建标题:

const headers = new HttpHeaders()
        .set("X-CustomHeader", "custom header value");

this.httpClient.get(yoururl,{params})/{params}的缩写形式{params:params}
或:
this.httpClient.get(yoururl,{headers:headers,params:params})

可以通过HttpParams发送参数:

const params = new HttpParams()
   .set('lat', 'one!')
   .set('lng', "two");  // and so on
可以通过以下方式创建标题:

const headers = new HttpHeaders()
        .set("X-CustomHeader", "custom header value");

this.httpClient.get(yoururl,{params})/{params}的缩写形式{params:params}
或:
this.httpClient.get(yoururl,{headers:headers,params:params})

即使GET请求在技术上可以有如本文所示的主体,但实际上并没有多少库支持它。正如您所指出的,CURL是这样做的。但是,前端API(如fetch、Xhr(XmlHttpRequest))将不允许在GET请求中发送正文

如果我没有弄错的话,Angular的HttpClient使用Xhr,所以不允许您这样做


您可以修改API以接受post请求,也可以接受查询字符串中的参数

,即使GET请求在技术上可以有如本文所示的主体,但实际上并没有多少库支持它。正如您所指出的,CURL是这样做的。但是,前端API(如fetch、Xhr(XmlHttpRequest))将不允许在GET请求中发送正文

如果我没有弄错的话,Angular的HttpClient使用Xhr,所以不允许您这样做


您可以修改API以接受post请求,也可以接受查询字符串中的参数,这是get方法。你说身体是什么意思?无法使用get-method从正文发送此为get-method。你说身体是什么意思?无法使用get方法从正文发送