【问题标题】:how to send a get request with a string parameter containing '/' in angular 4 service?如何在 Angular 4 服务中使用包含“/”的字符串参数发送获取请求?
【发布时间】:2018-06-26 05:40:30
【问题描述】:

我正在使用 angular 4 和 http 服务,我想调用一个服务并传递一个字符串以返回一个 JSON 值。我的字符串是“97/422/1883”,我的服务代码是:

getIncomingRelatedById(number) {
this.createAuthenticationHeaders();
return this.http.get(this.domain + '/mail/getIncomingRelatedById/' + number, this.options).map(res => res.json());

} 但是当我运行代码时,我收到以下错误:

http://localhost:3000/mail/getIncomingRelatedById/97/422/1883 404 (Not Found)

我现在如何发送我的请求?

更新:

在服务器端我有这个:

    router.get('/getRelatedById/:id', (req, res) => {
    pool.connect((err, client, done) => {
      if (err) {
        res.json({
          success: false,
          message: err
        });
      } else {
        client.query('select * from get_related_mail($1)', [req.params.id], 
         (err, mail) => {
          done();
          if (err) {
            console.log(err);
            res.json({
              success: false,
              message: err
            });
          } else {
          res.json({
            success: true,
            mail: mail,
          });
        });
      }
    });
  });

【问题讨论】:

  • 你如何在服务端检索它?
  • @Esco 如果你指的是服务器端,我编辑了我的帖子!
  • 我将把“/”替换为“-”。 mystring = mystring.replace(/\//g, "-");
  • @Eliseo 它正在工作!好主意!

标签: angular url parameters httpservice


【解决方案1】:

我认为这个链接很有帮助 https://www.w3schools.com/tags/ref_urlencode.asp

this like 包含所有字符和值

对于您的问题,这是您的角色 '/'==>'%2F'

【讨论】:

    猜你喜欢
    • 2010-12-07
    • 2017-01-04
    • 2020-02-04
    • 1970-01-01
    • 1970-01-01
    • 2021-05-04
    • 2012-02-16
    • 2014-09-26
    • 1970-01-01
    相关资源
    最近更新 更多