Upload картинки CURL'ом для Яндекс.Картинок

LEXAlForpostl

Мой дом здесь!
Регистрация
21 Май 2008
Сообщения
766
Реакции
228
Здравствуйте.
Подскажите, пожалуйста, как загрузить изображение для Яндекс.Картинок, чтобы использовать в последующем для поиска.
Вот запрос, который показывает HttpHeaders:
Для просмотра ссылки Войди или Зарегистрируйся

POST /yandsearch?rpt=imagecbir HTTP/1.1
Host: images.yandex.ru
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Accept-Encoding: gzip, deflate
X-Requested-With: XMLHttpRequest
Referer: Для просмотра ссылки Войди или Зарегистрируйся
Content-Length: 243382
Content-Type: multipart/form-data; boundary=---------------------------17520267414729
Cookie: [removed]
Connection: keep-alive
Pragma: no-cache
Cache-Control: no-cache
-----------------------------17520267414729
Content-Disposition: form-data; name="upfile"; filename="Cadillac10.jpg"
Content-Type: image/jpeg

yOya
HTTP/1.1 200 OK
Date: Sat, 25 Jan 2014 17:11:21 GMT
X-Yandex-Items-Count: 15
Cache-Control: private
X-Content-Type-Options: nosniff
X-Frame-Options: DENY
Vary: Accept-Encoding
Content-Encoding: gzip
Content-Type: application/x-javascript; charset=utf-8
Transfer-Encoding: chunked
[/spoil]
Буду безмерно благодарен за помощь.

UPD.
Следующий код выдает 417 ошибку.
PHP:
$uagent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
$postdata = array('upfile' => '1.jpg');
$url = 'http://images.yandex.ru/yandsearch?rpt=imagecbir';
$ch = curl_init( $url );
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
//curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
//curl_setopt($ch, CURLOPT_ENCODING, "utf8");
curl_setopt($ch, CURLOPT_USERAGENT, $uagent);
//curl_setopt($ch, CURLOPT_TIMEOUT, 120);
//curl_setopt($ch, CURLOPT_FAILONERROR, 1);
//curl_setopt($ch, CURLOPT_AUTOREFERER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postdata);
curl_setopt($ch, CURLOPT_COOKIEJAR, "coo.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE,"coo.txt");
$content = curl_exec( $ch );
$err = curl_errno( $ch );
$errmsg = curl_error( $ch );
$header = curl_getinfo( $ch );
curl_close( $ch );
$header['errno'] = $err;
$header['errmsg'] = $errmsg;
$header['content'] = $content;
var_dump ($header);

Ошибка:
[spoil]
array(24) {
["url"]=>
string(48) "Для просмотра ссылки Войди или Зарегистрируйся"
["content_type"]=>
NULL
["http_code"]=>
int(417)
["header_size"]=>
int(63)
["request_size"]=>
int(297)
["filetime"]=>
int(-1)
["ssl_verify_result"]=>
int(0)
["redirect_count"]=>
int(0)
["total_time"]=>
float(1.134639)
["namelookup_time"]=>
float(0.003618)
["connect_time"]=>
float(0.068364)
["pretransfer_time"]=>
float(0.068365)
["size_upload"]=>
float(146)
["size_download"]=>
float(0)
["speed_download"]=>
float(0)
["speed_upload"]=>
float(128)
["download_content_length"]=>
float(-1)
["upload_content_length"]=>
float(146)
["starttransfer_time"]=>
float(1.069423)
["redirect_time"]=>
float(0)
["certinfo"]=>
array(0) {
}
["errno"]=>
int(0)
["errmsg"]=>
string(0) ""
["content"]=>
string(0) ""
}
 
Последнее редактирование:
Добавь
Код:
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
 
Назад
Сверху