A
A
alex--n2017-06-20 14:43:15
PHP
alex--n, 2017-06-20 14:43:15

Why does it return 404 if the url is correct?

Good afternoon. You need to parse images from the site. I have a list of links and in the code I'm trying to issue a request in the form:

$value = removeBOM($value);
$str = 'http://mysite.ru/'.$value;
$sContent = file_get_contents($str);

removeBOM removes encoding marker bits. I have $value, which is issued in a cycle from a csv file (everything is in order with it and gives out what is needed). When executed, it proudly writes to me:
failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
A direct link with the same characters is fine. I am writing a parser for the first time, so everything may not be as it should)
What could be?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Sergey Pugovkin, 2017-06-20
@Driver86

1) var_dump ($value) should be done and make sure that the visible length matches the real one.
2) urlencode
3) punycode
file_get_contents, unlike the browser, does not encode the url, does not cut out invisible characters (at the end of $ value there may be a line break), and passes the encoding as is, which is critical for site.ru/url- Russian.

A
Andrey Prozorov, 2017-06-20
@i_d_1

It seems to me that the encoding bits should be removed from the file and from the value variable.
In addition, it is possible in the PHP settings that it is forbidden to receive files cross-domain. Check
with Ideshka see what goes into str

N
Nikita Shelkovnikov, 2017-06-20
@sholkyman

Have you tried it without removeBOM?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question