由于[object%20Object]被添加到url请求中而不是我传递给它的参数而出现此错误:“ http://localhost:3000/api/cookies/ [object%20Object] ”
在服务器端,我有这个:
router.get('/cookies/:URL', (req, res) => {
request.get(req.params.URL, function (err, response, body) {
if (err) {
return res.status(501).json(err);
} else {
const cookies = response.headers['set-cookie'];
if (cookies) {
return res.status(200).json(cookies);
}
}
});
});
在客户端: cookiesservice.ts:
getCookies(URL) {
return this.http.get(`${this.serverAPI}/cookies/` + URL).map(res => res.json());
}
cookies.component.ts:
searchCookies(URL) {
this.cookieService.getCookies(URL).subscribe();
}
cookies.component.html:
<form id="formData" #cookieData="ngForm">
<mat-input-container>
<input matInput placeholder="URL" name="URL" [(ngModel)]="cookieData.URL">
</mat-input-container>
<button mat-button type="button" id="searchCookies" (click)="searchCookies(cookieData.value)">Search</button>
</form>
对这个问题有任何想法吗?谢谢!