首页 > 解决方案 > 将文本编码为 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
  1. 首先,我认为存在一些编码问题。但是,它通过编码与其他文本一起工作。

  2. 其次,我认为可能是多个空格或特殊字符导致了这个问题。但是,它也适用于其他文本,如。

     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 替换 (-) 到空间。但是,我很想知道为什么这种行为很奇怪?

我确信这可能是因为"and" 后跟空格 %20and

=====更新======

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`下

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

在conf.d下

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

dockerfile

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

标签: node.jsexpressnginx

解决方案


推荐阅读