AT&T Video Optimizer
Best practices for resolving an HTTP 400 error bad request
Introduction
Sometimes you'll click on a link or visit a website only to get a message that there's an issue with the link. This message is called an "HTTP status code," which is often used interchangeably with the term "HTTP status line," but they are slightly different. The HTTP status line is more complete and contains two parts:
- The HTTP status code (e.g. 404).
- The HTTP reason phrase (e.g. requested page doesn't exist).
The reason phrase may vary from site to site. For example, a 404 status line might say “Not Found,” “Not_Found,” or “File Not Found.” What do you do when you get one of those messages and how do you know if it's user error or something that's happening with the site you're visiting? This article discusses best practices to help identify and fix common 4xx HTTP status codes and what to do when a remedy doesn't work.
4xx vs. 5xx Status Codes
A 4xx code (also known as 400 errors and 400 series errors) means the problem originated with the user, a 5xx code means the problem was caused by the server. With a 4xx code, typically the client or user has to fix an error before trying again, but there are some exceptions. With a 5xx code, the request can be present with no changes and you will get the requested result when the server has been fixed. You can read about best practices for 5xx codes.
For information about all status codes, see the Internet Assigned Numbers Authority’s (IANA) HTTP Status Code Registry or the W3C’s HTTP Status Codes Definitions.
Common 4xx Status Codes, Probable Causes, and Possible Solutions
Since user error is often what triggers a 4xx status code, we put together a list of things you can do to remedy the situation if it happens to you. For all status codes below, if the listed solutions don’t work, clear the cache and cookies to make sure those aren’t causing the error.
If the client computer has recently been upgraded or changed, consider if those changes might be causing the error. Also check to see if you need to upgrade the browser. If neither of those were the culprit and the fixes listed below aren't working, contact the website, or check the company's Twitter feed or Facebook page to see if the issue is on their side. Either other people are tweeting about the issue or the company has put up some information about the problem on their social media sites.
Code: 400 Bad Request
Probable cause: The server can’t process the request because of an error that’s caused by the client (e.g. incorrect URL syntax, invalid message framing, or deceptive request routing).
Possible Solutions:
- Check the URL for the following:
- Unsafe characters: " < > # % { } | \ ^ ~ [ ] ` and space
- Reserved characters (; / ? : @ = &) used incorrectly (i.e. unencoded* when not used for their defined purpose)
- Unecoded ASCII control characters
- The World Wide Web Consortium (W3C) has more information on encoding.
- Non ASCII characters
- Clear your DNS cache, in case your computer is storing outdated DNS information.
- Troubleshoot it as if it’s a 504 gateway error.
*Unencoded refers to the defined meaning of the characters. For example, using / indicates a new directory (aka folder) or a file name in a URL. So https://hackathon.com/winner/pictures/teamawesome.jpg means you want to see a picture named teamawesome.jpg which is inside the directory "pictures," which itself is inside the directory "winner." If you want to use / as part of a file or folder name, it has to be encoded so the server understands you aren’t indicating a new subdirectory or the start of a file name. The encoded value for / is /. If the picture was named teamawesome/dallashackathon.jpg, the URL would have to end with teamawesome/dallashackathon.jpg so the server won't think you are looking for a subdirectory named "teamawesome" with a photo named "dallashackathon.jpg " inside of it.
Note: It’s best practice to avoid reserved characters in a URL
Code: 401 Unauthorized
Probable cause: The item requested requires authentication.
Possible Solutions:
- If you have an account, login to the website and try again.
- You can include the authentication information in a URL, but there are security concerns with exposing login information sent via an HTTP request.
Code: 403 Forbidden
Probable cause: The requested file is not available to view.
Possible Solutions:
- Make sure you are requesting a file and not a directory (i.e. ensure the file name extension, such as .jpg, is present).
- Verify the URL.
- Check with the file’s owner to find out what are the requested file's permission settings.
- Check with the file’s owner whether the requested file has been protected.
Code: 404 Not Found
Probable cause: The file doesn’t exist.
Possible Solutions:
- Check for errors in the URL (i.e. a typo).
- Move up one level until something loads. This may help pinpoint the location of the typo.
- Reload (it may have been a temporary glitch).
H2: Other 4xx Status Codes
The codes listed below are rare, but do occur occasionally.
Code: 408 Timeout
Probable cause: The client didn’t produce a request within the time that the server was prepared to wait.
Possible Solutions:
- Reload.
- Visit other websites to see if the same thing happens. If so, it’s related to the network connection or caused by congestion.
- Try again later.
Code: 410 Gone
Probable cause: The file was removed from the server
Possible Solutions:
- Update the URL. This error code is used when a file has been intentionally deleted and won’t be re-added.
Code: 405 Method Not Allowed
Probable cause: A request method isn’t supported for the resource requested. 405 errors most often occur with the POST method.
Possible Solutions:
- Not all ISPs allow the POST method necessary to process the form. Remove the POST request.
- If POST is not being used, contact the website to see which methods are allowed or not allowed.
Code: 407 Proxy Authentication Required
Probable cause: The client must first authenticate itself with a proxy server. Authentication may require a login, a login/password, or another form of validation.
Possible Solutions:
- Treat it like a 401, but with the proxy server.
For the remaining 4xx status codes listed below, contact the website* to diagnose and resolve the issue as the problem may be on their end.
- 412 Precondition Failed
- 413 Payload Too Large
- 414 URI Too Long
- 415 Unsupported Media Type
- 416 Range Not Satisfiable
- 417 Expectation Failed
- 421 Misdirected Request
- 422 Unprocessable Entity
- 423 Locked
- 424 Failed Dependency
- 426 Upgrade Required
- 428 Precondition Required
- 429 Too Many Requests
- 431 Request Header Fields Too Large
- 451 Unavailable For Legal Reasons
*Contact information for most websites can be found by running a whois query on the site’s URL.
AT&T Video Optimizer Can Help
AT&T Video Optimizer, a free diagnostic tool for optimizing mobile app performance, identifies all HTTP 4xx and 5xx status codes that are found in an application trace. These codes are an important part of application analysis, because they provide information about possible errors resulting from an HTTP request