Home > Article > Web Front-end > How to solve the node 400 error problem
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)".
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
encodeURI() function can encode a string as a URI.
encodeURI(URIstring)
Parameters | Description |
---|---|
URIstring | Required. A string containing the URI or other text to be encoded. |
A copy of the URIstring, with some characters replaced by hexadecimal escape sequences.
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: If the URI component contains delimiters, such as? and #, you should use the encodeURIComponent() method to encode each component separately.
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!