14,959
edits
m (Text replacement - ": Image:Owl icon.jpg " to "{{Tips}} ") Tags: Mobile edit Mobile web edit |
(How to resolve Error 400 Bad Request Errors: UTF-8 Character Encoding Issues) |
||
| Line 140: | Line 140: | ||
Proposed Solution | Proposed Solution | ||
* Instead of relying on the cURL command, switching to a JavaScript-based crawler is recommended as a solution to this problem <ref>[https://www.zenrows.com/blog/cloudflare-error-1010#how-to-avoid Cloudflare Error 1010: What Is It and How to Avoid - ZenRows]</ref>. | * Instead of relying on the cURL command, switching to a JavaScript-based crawler is recommended as a solution to this problem <ref>[https://www.zenrows.com/blog/cloudflare-error-1010#how-to-avoid Cloudflare Error 1010: What Is It and How to Avoid - ZenRows]</ref>. | ||
== How to resolve Error 400 Bad Request Errors: UTF-8 Character Encoding Issues == | |||
'''Problem Analysis:''' | |||
Example cURL command for Windows terminal with error: | |||
<pre> | |||
$ curl "https://api.search.brave.com/res/v1/web/search?q=\"XXX\"+公司簡介+產品+服務" \ | |||
-H "Accept: application/json" \ | |||
-H "Accept-Encoding: gzip" \ | |||
-H "X-Subscription-Token: YOUR_API_KEY_HERE" | |||
> <html><body><h1>400 Bad request</h1> | |||
Your browser sent an invalid request. | |||
</body></html> | |||
</pre> | |||
'''Solutions''' | |||
Properly Handle URL Encoding: Chinese characters and special symbols need to be correctly URL-encoded to avoid 400 Bad Request errors (online tool: [https://www.urlencoder.org/ URL Encode and Decode - Online]): | |||
* {{kbd | key=<nowiki>"XXX"</nowiki>}} → {{kbd | key=<nowiki>%22XXX%22</nowiki>}} | |||
* {{kbd | key=<nowiki>公司簡介</nowiki>}} → {{kbd | key=<nowiki>%E5%85%AC%E5%8F%B8%E7%B0%A1%E4%BB%8B</nowiki>}} | |||
* {{kbd | key=<nowiki>產品</nowiki>}} → {{kbd | key=<nowiki>%E7%94%A2%E5%93%81</nowiki>}} | |||
* {{kbd | key=<nowiki>服務</nowiki>}} → {{kbd | key=<nowiki>%E6%9C%8D%E5%8B%99</nowiki>}} | |||
'''Revised cURL Command:''' | |||
<pre> | |||
$ curl "https://api.search.brave.com/res/v1/web/search?q=%22XXX%22+%E5%85%AC%E5%8F%B8%E7%B0%A1%E4%BB%8B+%E7%94%A2%E5%93%81+%E6%9C%8D%E5%8B%99" \ | |||
-H "Accept: application/json" \ | |||
-H "Accept-Encoding: gzip" \ | |||
-H "X-Subscription-Token: YOUR_API_KEY_HERE" | |||
</pre> | |||
== How to resolve Error 405 Method Not Allowed == | == How to resolve Error 405 Method Not Allowed == | ||