开发者

Long URLs with more than 4095 characters in php

$url = "http://example.com/............."

The $url has about开发者_如何学Go more than 4095 characters . I need to access this URL in php, but if I use file or file_get_contents, it returns an error

How can i open or access this URL in php?


Your problem isn't PHP, it's the madness of your requirement. :) Also ;

What is the maximum length of a URL in different browsers?

Surely you want POST instead of crazy GET. This sounds more like a fundamental problem of the systems design.


It depends on server type, which you are trying to access.

For example:

Apache: limits URL length by LimitRequest*, by default it has 8 KBytes for URL string.

Microsoft Internet Information Server: by default it has 16 KBytes. But it can be changed.

Perl HTTP::Daemon: 8,000 chars for URL length and 16 KBytes for HTTP-header. Values can be changed in Daemon.pm.


the error you got was generated by the remote server ... that service can't handle URLs longer than the stated ammount of characters.

if that API relies on GET requests and is meant to be used the way you use it, your problem is a design error in the used API and has nothing to do with PHP. if you can not change the API or the service that provides access to the API, you can not solve this problem


You should be using POST instead of GET for such amounts of data

  1. Create stream context
  2. Set your context options
  3. Use this context as a 3rd param in file_get_contents()


As Raymond Chen once wrote, if you have to ask, you're probably doing something wrong. In your case, you should clearly be using POST instead of GET.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜