Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/svg/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 将文本编码到URL时的奇怪行为_Node.js_Express_Nginx - Fatal编程技术网

Node.js 将文本编码到URL时的奇怪行为

Node.js 将文本编码到URL时的奇怪行为,node.js,express,nginx,Node.js,Express,Nginx,我真的很空虚,无法理解这个场景 我的URL格式: http://api.xyz.com/pro/api/cities/Antigua%20and%20Barbuda 它返回: Could not get any response There was an error connecting to http://api.xyz.com/pro/api/cities/Antigua%20and%20Barbuda. Why this might have happened: The server c

我真的很空虚,无法理解这个场景

我的URL格式:

http://api.xyz.com/pro/api/cities/Antigua%20and%20Barbuda
它返回:

Could not get any response
There was an error connecting to http://api.xyz.com/pro/api/cities/Antigua%20and%20Barbuda.
Why this might have happened:
The server couldn't send a response:
Ensure that the backend is working properly
Self-signed SSL certificates are being blocked:
Fix this by turning off 'SSL certificate verification' in Settings > General
Proxy configured incorrectly
Ensure that proxy is configured correctly in Settings > Proxy
Request timeout:
Change request timeout in Settings > General
当我用实际IP和端口更改主机时,它会工作并返回所有城市:

http://10.10.10.10:9000/pro/api/cities/Antigua%20and%20Barbuda
  • 首先,我认为有一些编码问题。但是,它正在发挥作用 与其他人通过编码文本

  • 第二,我想可能是多个空格或特殊字符造成的 这个问题。但是,它也适用于其他文本,如

     http://api.xyz.com/pro/api/cities/Bolivia,%20Pluri%20State%20of
    
  • 到目前为止,我所观察到的是,“然后是空格”不起作用

    1. http://api.xyz.com/pro/api/cities/Bosnia%20and%20Herzegovina
    2. http://api.xyz.com/pro/api/cities/Heard%20Island%20and%20McDonald%20Mcdonald%20Islands
    
    但是,这些都是IP
    10.10.10.10:9000
    的请求,可以完美地工作

    我也尝试过使用查询参数进行更改。但是,同样的错误

    我有办法把空格换成(-),把BE换成(-)再换成空格。但是,我很想知道为什么这种行为很奇怪

    我确信这可能是因为“和”后跟空格
    %20和

    ====更新======
    nginx
    配置:

    server {
      listen 4200;
      gzip  on;
      gzip_types
      application/atom+xml
      application/javascript
      application/json
      application/rss+xml
      application/vnd.ms-fontobject
      application/x-font-ttf
      application/x-web-app-manifest+json
      application/xhtml+xml
      application/xml
      font/opentype
      image/svg+xml
      image/x-icon
      text/css
      text/plain
      text/x-component
      text/xml
      text/javascript;
      location / {
        root /usr/share/nginx/html;
        index index.html index.htm;
        try_files $uri $uri/ /index.html =404;
      }
      location ~*  \.(jpg|jpeg|png|gif|ico|css|js)$ {
            root /usr/share/nginx/html;
            expires 1d;
      }
    }
    
    在'nginx下` 在conf.d下 dockerfile
    如果直接通过IP访问节点服务工作正常,那么这很可能是您的代理(nginx、apache或您正在使用的任何东西)的问题。我建议您检查一下,可能是因为某些原因,或者更可能是因为您的URL配置不正确。@ElliotBlackburn没有任何特殊配置。我正在使用
    nginx
    。我需要检查什么样的配置?我不是NGinx专家,所以在您的问题中标记NGinx是值得的,但如果直接命中节点服务时没有发生此问题,但通过NGinx命中时发生此问题,那么您已经证明节点服务工作正常。是的,那么让我检查一下nginx的配置。你能发布你的nginx配置吗?
    drwxr-xr-x  2 root root 4096 Sep  6 08:44 conf.d
    -rw-r--r--  1 root root 1007 May 31  2016 fastcgi_params
    -rw-r--r--  1 root root 2837 May 31  2016 koi-utf
    -rw-r--r--  1 root root 2223 May 31  2016 koi-win
    -rw-r--r--  1 root root 3957 May 31  2016 mime.types
    lrwxrwxrwx  1 root root   22 May 31  2016 modules -> /usr/lib/nginx/modules
    -rw-r--r--  1 root root  643 May 31  2016 nginx.conf
    -rw-r--r--  1 root root  636 May 31  2016 scgi_params
    -rw-r--r--  1 root root  664 May 31  2016 uwsgi_params
    -rw-r--r--  1 root root 3610 May 31  2016 win-utf
    
    drwxr-xr-x 2 root root 4096 Sep  6 08:44 .
    drwxr-xr-x 4 root root 4096 Sep  6 08:44 ..
    -rwxrwxr-x 1 root root  634 Aug 31 11:24 default.conf
    
    FROM node:8.11.1 as claims
    COPY package.json package-lock.json ./
    RUN npm set progress=false && npm config set depth 0 && npm cache clean --force
    RUN npm i && mkdir /ng-app && cp -R ./node_modules ./ng-app
    
    ## Storing node modules on a separate layer will prevent unnecessary npm installs at each build
    # RUN mkdir ./ng-app/
    
    # RUN npm i @angular/cli@1.3.1
    # RUN npm i @angular/cli@1.3.1 -g
    # RUN npm install npm@5.1.0
    
    # RUN npm install
    
    WORKDIR /ng-app
    COPY . .
    ## Build the angular app in production mode and store the artifacts in dist folder
    RUN $(npm bin)/ng build
    
    # Stage 1, based on Nginx, to have only the compiled app, ready for production with Nginx
    FROM nginx:1.10.1
    
    COPY --from=claims /ng-app/dist/ /usr/share/nginx/html
    COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf