要求:使用 post 数据将数据发送到端点,并将 startdate 和 endate 放入 url 的查询字符串中,如下所示:
https://server/byLocation?startDate=2019-01-01&EndDate=2020-01-01
数据负载仅具有如下所示的 locationID 和 Criteria。
资源定义
我也尝试将 startDate 和 endate 移出查询对象。
ByLocationResource: $resource(
ByLocationEndpoint,
null,
{
query: {
startDate: '@startDate',
endDate: '@endDate',
locationIds: ['@locationIds'],
Criteria: '@Criteria',
method: 'POST'
}
}
),
端点定义
var ByLocationEndpoint = https:/servername/byLocation/?startDate=:startDate&endDate=:endDate');
如何将 URL 端点中的查询字符串与发布数据结合起来?
服务:
function ByLocation(startDate, endDate, Criteria, locationIds) {
_ByLocationResource.query(
{
startDate:startDate,
endDate:endDate,
locationIds: [locationIds],
Criteria: Criteria
});
}
我试过把事情混在一起有点像这样:
function ByLocation(startDate, endDate, Criteria, locationIds) {
_ByLocationResource(startDate,EndDate).query(
{
locationIds: [locationIds],
Criteria: Criteria
});
}
我是否被迫使用 $http 而不是端点和资源?
浏览器收到 400 错误请求,如下所示:
请求网址:https://servername/bylocation/?startDate=&endDate=
显然 startDate 和 endDate 参数没有被填写。