node.js - 将文本编码为 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 替换 (-) 到空间。但是,我很想知道为什么这种行为很奇怪?
我确信这可能是因为"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
解决方案
推荐阅读
- react-native - onSubmitEditing 在每次按键时触发
- c++ - BGR -> YCbCr 转换无法正常工作
- vue.js - 将数据传递给路由的组件 beforeEnter
- python - 异步使用时 Ansible 失败
- big-o - 如果我在 for 循环中的终止语句是 i < n * n ,那么我的运行时间是 O(n^2) 吗?
- python - 当 df 只有 1 行时,使用 np.column_stack 创建数据框
- java - 此代码的答案对于每个输入都是错误的,无论它是正确还是错误
- java - 为什么在这个树遍历中只有 log(N) 递归调用?
- image - 如何在mac上压缩(调整大小?)> 60k图像?
- javascript - 嵌套for循环功能