我有以下用于搜索的REST API(json对象),我应该在URL中构建一个POST请求,以下REST API的url参数是什么?仅仅因为它的嵌套我不知道如何构建包含问号或等号的URL。
http://localhost:63020/api/search ....?
{
"offset": 0,
"batchsize": 10,
"search": {
"scope": [2,3,32],
"type": "basic",
"text": {
"value": "test*",
"fields": [
"subject", "body"
]
},
"age": {
"unit": "d",
"amount": 365
},
"hasattachments": false,
},
"facet": "messagehits",
}
答案 0 :(得分:0)
因为您想要使用Post请求,无需修改您的URL(https://www.w3schools.com/tags/ref_httpmethods.asp),只需将其作为文档正文传递,然后在服务器端处理。
答案 1 :(得分:0)
好的,所以在Anagular 4中弄清楚我正在使用HTTP客户端模块,我做了什么我只是将整个对象作为参数传递回来,我得到了回复,这很简单,请参阅以下代码:
sampleSearch(){
this.http.post('/api/search/', {
"offset": 0,
"batchsize": 10,
"search": {
"scope": [2,3,32],
"type": "basic",
"text": {
"value": "test*",
"fields": [
"subject", "body"
]
},
"age": {
"unit": "d",
"amount": 365
},
"hasattachments": false,
},
"facet": "messagehits",
}
).map(data => data).subscribe(
res => {
console.log(res);
},
err => {
console.log("Error occured");
}
);
}