I use the file_get_contents() function in PHP. When the length of the url string is not large, then everything works. But I need to make a request on the API of a single site, in which elements from the url string are sent. And when I try to make a request with a link length of approximately 3 thousand characters, I get an error

 Warning: file_get_contents(''): failed to open stream: HTTP request failed! HTTP/1.1 403 

I do not understand what the problem is and how to solve it.

The link in urlencode() wrapped, and if you enter it in the browser, the request is processed normally. Maybe you need to change something in ini_set() or somewhere else?

1 answer 1

Perhaps the problem is as follows:

  • as the method of sending data you use the method GET, use the method POST. Using GET is better to send small test data. The maximum amount here is 4 KB. There is no such restriction for POST.

  • also in the settings of the server itself, there is a limit on the size of the transferred files, you need to check this parameter.

  • server expects one data transfer method and you use another