How to solve the node 400 error problem

藏色散人
Release: 2021-12-10 13:43:53
Original
2281 people have browsed it

Node 400 error solution: 1. Check the nodeJS request HTTP error message; 2. Use the JavaScript encodeURI() function to encode the URL containing Chinese, using syntax such as "encodeURI(URIstring)".

How to solve the node 400 error problem

The operating environment of this article: Windows 7 system, nodejs version 10.16.2, Dell G3 computer.

How to solve the node 400 error problem?

nodeJS request HTTP error: 400, please use the JavaScript encodeURI() function to encode the URL containing Chinese

JavaScript global object

Definition and usage

encodeURI() function can encode a string as a URI.

Syntax

encodeURI(URIstring)
Copy after login
Parameters Description
URIstring Required. A string containing the URI or other text to be encoded.

Return value

A copy of the URIstring, with some characters replaced by hexadecimal escape sequences.

Description

This method does not encode ASCII letters and numbers, nor does it encode these ASCII punctuation characters: - _ . ! ~ * ' ( ) .

The purpose of this method is to completely encode the URI, so the encodeURI() function will not escape the following ASCII punctuation marks that have special meanings in the URI: ;/?:@& = $,

#Tips and comments

Tips: If the URI component contains delimiters, such as? and #, you should use the encodeURIComponent() method to encode each component separately.

Example

In this example, we will use encodeURI() to encode the URI:

<script type="text/javascript">

document.write(encodeURI("http://www.w3school.com.cn")+ "<br />")
document.write(encodeURI("http://www.w3school.com.cn/My first/"))
document.write(encodeURI(",/?:@&=+$#"))

</script>
Copy after login

Output:

http://www.w3school.com.cn
http://www.w3school.com.cn/My%20first/
,/?:@&=+$#
Copy after login

Recommended learning:《node.js video tutorial

The above is the detailed content of How to solve the node 400 error problem. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template