Cloudflare's 1020 error code indicates the request was blocked for potential malicious activity or violating bot protection rules. This can cause headaches when testing APIs with tools like JMeter or Postman. However, with a few tweaks you can get past the blocks and resume testing.
Why Cloudflare Blocks Automated Tools
Cloudflare aims to protect websites from attacks and abuse. Automated tools like JMeter and Postman can sometimes trigger the protections if sending too many requests too quickly or missing browser fingerprints. The 1020 block acts as a caution sign to slow things down.
Adjusting JMeter Settings
Here are some tips for configuring JMeter to avoid triggers:
Here is an example setup:
HTTP Header Manager
User-Agent: Mozilla/5.0 Firefox/87.0
Accept-Language: en-US
HTTP Cookie Manager
HTTP Request Defaults
Connect Timeout: 10000
Response Timeout: 60000
CSV Data Set Config
ip_list.csv, user-agents.csv
Throughput Controller
Max Requests Per Minute: 10
Postman Settings to Avoid Blocks
For Postman, enabling the Interceptor can help mimic a real browser:
Also add Variabilities like different User-Agents and Languages. Start with a small runs first before larger load tests.
Confirm It's a Cloudflare 1020 Block
Before tweaking settings, confirm the issue is actually a 1020 block using a browser or cURL. For example:
$ curl -I https://example.com/api/test
HTTP/2 1020
cache-control: no-cache
content-type: text/html
The 1020 status code indicates Cloudflare is blocking the request.
Getting Unblocked After Tweaks
After adjusting JMeter and Postman settings to mimic a browser, try your tests again starting slowly. The blocks should reduce or go away completely.
If still blocked, you can contact the target website to whitelist the IP addresses used for testing.
Caveats to Know
A few things to keep in mind when troubleshooting 1020 errors:
So always check if you are blocked after making any major changes to tests.
Key Takeaways
With the right tweaks you can minimize blocks and resume API testing through Cloudflare protections. Just take care to throttle traffic and not trigger the abuse alarms!