Home >Web Front-end >Front-end Q&A >How to solve the node 400 error problem

How to solve the node 400 error problem

藏色散人
藏色散人Original
2021-12-10 13:43:532304browse

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)
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>

Output:

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

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!

Statement:
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