将值[object%20Object]添加到请求而不是请求参数中

时间:2018-06-20 19:39:32

标签: node.js express request

由于[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>

对这个问题有任何想法吗?谢谢!

0 个答案:

没有答案