Warning: Cannot use a scalar value as an array in /home/admin/public_html/forum/include/fm.class.php on line 757

Warning: Invalid argument supplied for foreach() in /home/admin/public_html/forum/include/fm.class.php on line 770
Форумы портала PHP.SU :: Версия для печати :: Помощь с сURL
Форумы портала PHP.SU » » Работа с сетью » Помощь с сURL

Страниц (1): [1]
 

1. Kreks - 17 Июня, 2012 - 16:14:55 - перейти к сообщению
Приветствую. Задача : Авторизироваться и после авторизации по другому URL загрузить картинку.

Набросал код

PHP:
скопировать код в буфер обмена
  1.  
  2.  
  3. $UrlSession = "http://test1.ru/sias/sws.php?method=session.login";
  4. $UrlUpload = "http://test1.ru/sias/sws.php?method=image.add";
  5. $upload = 'Z:\home\test1.ru\www\SendCurl\1.jpg';
  6. $postdata = array('upload' => "@".$upload.";type=image/jpeg");
  7.  
  8. // создаем оба ресурса cURL
  9. $ch1 = curl_init();
  10. $ch2 = curl_init();
  11.  
  12. // устанавливаем URL и другие соответствующие опции
  13. curl_setopt($ch1, CURLOPT_URL, "$UrlSession");
  14. curl_setopt($ch1, CURLOPT_HEADER, 0);
  15. curl_setopt($ch1, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; rv:11.0) Gecko/20100101 Firefox/11.0');
  16. curl_setopt ($ch1, CURLOPT_COOKIEJAR, 'Z:\home\test1.ru\www\SendCurl\cookie.txt');
  17. curl_setopt ($ch1, CURLOPT_COOKIEFILE, 'Z:\home\test1.ru\www\SendCurl\cookie.txt');
  18. curl_setopt($ch1, CURLOPT_POST, 1);
  19. curl_setopt($ch1, CURLOPT_POSTFIELDS, "username=Kreks&password=778899");
  20. curl_setopt($ch1, CURLOPT_RETURNTRANSFER  ,1);
  21.  
  22.  
  23.  
  24. curl_setopt($ch2, CURLOPT_URL, "$UrlUpload");
  25. curl_setopt($ch2, CURLOPT_HEADER, 0);
  26. curl_setopt ($ch2, CURLOPT_COOKIEFILE, "Z:\home\test1.ru\www\SendCurl\cookie.txt");
  27. curl_setopt ($ch2, CURLOPT_COOKIEJAR, "Z:\home\test1.ru\www\SendCurl\cookie.txt");
  28. curl_setopt ($ch2, CURLOPT_RETURNTRANSFER, 1);
  29. curl_setopt ($ch2, CURLOPT_FAILONERROR, 1);
  30. curl_setopt ($ch2, CURLOPT_CONNECTTIMEOUT, 30);
  31. curl_setopt($ch2, CURLOPT_POST, 1);
  32. curl_setopt($ch2, CURLOPT_POSTFIELDS, $postdata);
  33.  
  34. //создаем набор дескрипторов cURL
  35.  
  36. //добавляем два дескриптора
  37.  
  38. $running=null;
  39. //запускаем дескрипторы
  40. do {
  41.     curl_multi_exec($mh,$running);
  42. } while($running > 0);
  43.  
  44. //закрываем все дескрипторы
  45.  
  46. if(curl_error($ch2)){
  47.     echo 'Ошибка curl: ' . curl_error($ch2);
  48. }
  49.  
  50.  
  51.  


Выдает ошибку запроса 501(The requested URL returned error: 501) то есть ошибка передаваемого типа Content-Type,хотя я передаю ему(type=image/jpeg) Вопрос как исправить? Может можно как то cURL передать тип ?

 

Powered by ExBB FM 1.0 RC1