'file_get_contents() without "Http" to access external URL [closed]

I'm attempting to access an external URL (API)

echo file_get_contents("http://...");

However, I want to request this URL without the "Http://" - this causes it to run slower, (not sure as to why). if I remove the http:// from the parameter it can't find the file (understandably)

Any ideas?

php


Solution 1:[1]

@jack-hardcastle, based on the comments below your question: try to increase timeout.
I tried to load the URL provided by you in Chrome on my machine and after a big while of loading, it showed me probably correct response.

Here's how you increase the HTTP timeout for file_get_contents():

<?php

$ctx = stream_context_create(array(
    'http' => array(
        'timeout' => 16.0 // seconds
    )
));

$contents = file_get_contents('http://...', FALSE, $ctx);

// do something with $contents

I also tried to find out what are the missing headers for which runescape services may check; thus I wrote a simple script sending a simple GET request against httpbin.org:

$ ./test
{
  "headers": {
    "Host": "httpbin.org"
  }
}

$ cat test
#!/usr/bin/env php
<?php

die(file_get_contents('http://httpbin.org/headers'));

Suprise: The only header sent by file_get_contents() is Host. So there might be really anything in headers that is missing for runescape services.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kubo2