The communication between the client browser and web server can have different types of problems. The web server returns 4xx HTTP status codes whenever there are errors in processing the request received from the browser. The web server sends a 400 Bad or Invalid Request HTTP response if it can’t process the request from the client browser. This generally happens due to invalid syntax of the request.
As an end user, getting this error while accessing an important website can be quite frustrating. You will see HTTP response codes on the browser because of complex relationship between website server, user devices and third party services. So, it could be difficult to determine the actual cause of the problem, even if you have a controlled environment. However, in most situations it is fairly easy to dig into the actual root cause.
Learn more on what is HTTP, structure of HTTP request and response.
How to Fix 400 Bad or Invalid Request HTTP Error?
Here are things you can do to fix 400 bad or invalid request error.
- Refresh your webpage
- Check the URL
- Delete cookies and cache
- Flush DNS
- Check file size limit on uploading
- Open other websites
- Restart your devices
- Check HTTP headers
- Check server log
- Debug scripts on custom applications
A. For Normal Users
If you are a normal internet user and getting 400 error on the browser then follow the below solutions.
1. Refresh the Page
If you have problems accessing a page, refreshing it may worth a shot. In most cases, the 400 Bad or Invalid Request HTTP error is temporary. With most browsers, you can press the F5 key for refreshing the page. if it does not fix your problem immediately, refresh the page two or three times may sometimes work.
2. Check Your URL
If you are typing the URL on the address bar then chances are there to make a spelling mistake. The 400 Bad or Invalid Request HTTP error can happen due to mistyped URL. It is also possible that the link has mistyped URL or your bookmarked page URL is wrong.
Check the address manually and see if there are obvious errors. If you are not certain about the correct URL of the page, try to find it from Google search results. You may have some keywords that could be associated with the webpage. Search the page with unique keywords to improve your chance of finding the page.
3. Remove Cookies and Cache
The 400 Bad or Invalid Request HTTP error could happen if your cookies are outdated or corrupted. Some browser extensions may change the cookies and causing errors. So, your browser has a corrupted version of the cache. Try to clear the cookies and cache of your website. After clearing cache, pages may load a bit slower, because your browser will need to rebuild the cache with often-accessed data. But this could help to fix the problem.
Remember, when you clear cookies, you may need to retype login information for all websites. You need different procedure to clear cache and cookies for each web browser. Generally, pressing “Command + Shift + Delete” in Mac and “Control + Shift + Delete” in Windows will work on Chrome and Firefox browsers.
Learn more about clearing browsing history on popular browsers.
4. Flush DNS
Your computer may have outdated DNS records and this could cause errors. You can flush the DNS and check whether that solve the 400 HTTP error issue. It’s easy to do and won’t cause unwanted problems.
- Make sure that you run the computer as computer’s administrator
- Type in CMD in the Windows Search box and open Command Prompt.
- In the command interface, type in ipconfig /flushdns and press Enter.
Learn detailed information on how to flush DNS in Windows and Mac.
5. Check File Size When Uploading
The 400 Bad or Invalid Request HTTP error could happen when you try to upload a big file. First check the allowed file size for uploading. If your file is bigger, you can split it with file splitter utility and upload file parts individually.
6. Check Other Websites
If you keep on getting the 400 Bad or Invalid Request HTTP error when trying to open a webpage, you should check whether it also happens with other websites. If the error appears again, then there could be a problem with networking devices on your computer. On Windows computer, run Network Diagnosing Utility to fix the connection problem. On Mac, you may need to disconnect and reconnect the device.
You may also contact the Internet service provider to find out whether they could resolve the problem.
7. Restart Your Devices
This may be a hit and miss. However, restarting your networking equipment and computer could help you to fix the 400 Bad or Invalid Request HTTP error.
B. For Developers
If you are a developer, you may get 400 HTTP error when testing your own application. Follow the below options to fix the error.
8. Fix Invalid HTTP Headers
Sometimes inspecting HTTP header details may give you clue on the connection error. You can view the HTTP header details using one of the free tools on the web. Though this is easy to do for developers, it can be quite tricky for non-developers.
9. Check Server Logs
Web servers usually keep server side logs for each request that a client sends. The log may contain information such as the connected application, requested pages, IP address and other relevant information of the requests. Server logs often identify the reason for the failure and indicates the processing status. By looking at the server logs, developers and administrators can easily identify the root of the HTTP problems.
If you don’t have access to server log files, request the access to your hosting provider.
10. Debug Scripts or Application Code
If you are getting the error on custom applications then it could be due to the poorly written code in the application. Developers need to debug the application manually and check server logs to identify potential problems.
Having a good error management system can effectively help to resolve the 400 Bad or Invalid Request HTTP error for developers. Even if errors happen, you can detect them automatically. For example, Airbrake is a good error monitoring system that offers real-time updates. It has an excellent dashboard that offers round the clock updates on the health of your web application. With customizable error filter, you can get updates about errors that matter most.
As explained above 400 error happens due to sending invalid request to server. It could be due to file upload or corrupted browser cookies. Follow the above listed solutions and we hope one of it should help you to fix the problem. If the problem persists, it could also be due to the additional third party factors between your browser and the server. Wait for some time and try later to access the webpages.
On custom applications, developers may take step by step debugging process to find the actual problem.