CURL грешка

dakata__92

Super Moderator
Това е текста на съобщението:
Received HTTP code 302 from proxy after CONNECT
Защо се получава?
PHP:
class CurlResponse 
{
	private $array = array(
		"useragent" => "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16",
		"referer" => "https://www.google.bg/?gws_rd=ssl",
		"proxy" => "",
		"proxyport" => "",
		"postfields" => ""
	);
	
	public function __construct()
	{
		
	}
	
	public function setResponseOption(Array $array)
	{
		$this->array = array_merge($this->array,$array); 
	}
	
	public function getResponse($url){
		$ch = curl_init($url);
		$options = array(
			CURLOPT_CONNECTTIMEOUT => null, 
			CURLOPT_USERAGENT => $this->array["useragent"],
			CURLOPT_REFERER => $this->array["referer"],
			CURLOPT_PROXY => $this->array["proxy"],
			CURLOPT_PROXYPORT => $this->array["proxyport"],
			CURLOPT_HTTPPROXYTUNNEL => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_SSL_VERIFYPEER => false,
			CURLOPT_SSL_VERIFYHOST => false
		);
		if ($this->array["postfields"]) {
			array_push(
				$options,
				array(
					CURLOPT_POST => true,
					CURLOPT_POSTFIELDS => $this->array["postfields"]
				)
			);
		}
		curl_setopt_array($ch, $options);
		if (!$html = curl_exec($ch)) {
			$html = curl_error($ch);
		}
		curl_close($ch);
		return $html;
	}
}
 
joTunkiq каза:
Код:
 curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

в твоя случай:
PHP:
CURLOPT_FOLLOWLOCATION => true
:idea: :?:

Стана! Имам сега друг проблем. Искам да постна ето тази форма но не успявам:
HTML:
<form method='post' name='vote'>
<input type='hidden' name='n' value='maksui' />
<button type='submit' class='submit' style='width:150px;'>Потвърждавам</button>
</form>

Проблема е, че не праща пост заявка и не успявам да взема правилната информация от страницата, все едно не натиска бутона.

PHP:
ini_set('memory_limit', '-1');
ini_set('max_execution_time', 0); 

class CurlResponse 
{
	private $array = array(
		"useragent" => "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16",
		"referer" => "https://www.google.bg/?gws_rd=ssl",
		"proxy" => "",
		"proxyport" => "",
		"postfields" => ""
	);
	
	public function __construct()
	{
		
	}
	
	public function setResponseOption(Array $array)
	{
		$this->array = array_merge($this->array,$array); 
	}
	
	public function getResponse($url){
		$ch = curl_init($url);
		$options = array(
			CURLOPT_USERAGENT => $this->array["useragent"],
			CURLOPT_REFERER => $this->array["referer"],
			CURLOPT_PROXY => $this->array["proxy"],
			CURLOPT_PROXYPORT => $this->array["proxyport"],
			CURLOPT_HTTPPROXYTUNNEL => true,
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_SSL_VERIFYPEER => false,
			CURLOPT_SSL_VERIFYHOST => false
		);
		if ($this->array["postfields"]) {
			array_push(
				$options,
				array(
					CURLOPT_POST => true,
					CURLOPT_POSTFIELDS => http_build_query($this->array["postfields"])
				)
			);
			print http_build_query($this->array["postfields"]);
		}
		curl_setopt_array($ch, $options);
		if (!$response = curl_exec($ch)) {
			$response["error"] = curl_error($ch);
			$response["errno"] = curl_errno($ch);
			$response["info"] = curl_getinfo($ch);
			$response = print_r($response,true);
		}
		curl_close($ch);
		return $response;
	}
}
print '<pre>';
$cr = new CurlResponse();
$cr->setResponseOption(array(
	"postfields" => array("n" => "maksui")
));
$html = $cr->getResponse("http://example.com/u:maksui");
print $html;
 
Така смалих кода но отново проксито не работи:
PHP:
function getResponse($url){
		$ch = curl_init($url);
		$options = array(
			CURLOPT_USERAGENT => "Opera/9.80 (X11; Linux i686; Ubuntu/14.10) Presto/2.12.388 Version/12.16",
			CURLOPT_REFERER => "https://www.google.bg/?gws_rd=ssl",
			CURLOPT_POST => true,
			CURLOPT_POSTFIELDS => http_build_query(array("n" => "Hyuskata")),
			CURLOPT_HTTPPROXYTUNNEL => true,
			CURLOPT_PROXY => "92.247.127.57",
			CURLOPT_PROXYPORT => "1080",
			CURLOPT_FOLLOWLOCATION => true,
			CURLOPT_RETURNTRANSFER => true,
			CURLOPT_SSL_VERIFYPEER => false,
			CURLOPT_SSL_VERIFYHOST => false
		);
		
		curl_setopt_array($ch, $options);
		if (!$response = curl_exec($ch)) {
			$response["error"] = curl_error($ch);
			$response["errno"] = curl_errno($ch);
			$response["info"] = curl_getinfo($ch);
			$response = print_r($response,true);
		}
		curl_close($ch);
		return $response;
	}
	$html = getResponse("http://example.com/u:Hyuskata");
	preg_match("/\<div class=\'msg\-ok\' style=\'clear\:both\;\'\>(.+)<\/b>/i",$html,$match);
	print isset($match[1]) ? $match[1] : "Вече е гласувано!";
 
uphero каза:
dakata__92 каза:
Никой ли незнае как да се поства през прокси с CURL? :(
Целта не ми харесва, спама и манипулирането не са сред любимите ми неща/

То ако става дума за спам съм свалял сайтове с него, манипулиране, не правя такова. То ако става дума за цели, отдавна съм написал система за откриване на информация за дадено лице онлайн. Просто питам за решение на въпроса ми дали мога да създам собствено прокси приложение да поства през него, пък това за какво ще се ползва е абсолютно относително, като почти всеки код ползващ се за добро и лошо. Та въпроса ми е какъв е проблема?
 
PHP:
function curlFile($url,$proxy_ip,$proxy_port,$loginpassw)
{
    //$loginpassw = 'username:password';
    //$proxy_ip = '192.168.1.1';
    //$proxy_port = '12345';
    //$url = 'http://www.domain.com';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
    curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
    curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

? :idea:
 
joTunkiq каза:
PHP:
function curlFile($url,$proxy_ip,$proxy_port,$loginpassw)
{
    //$loginpassw = 'username:password';
    //$proxy_ip = '192.168.1.1';
    //$proxy_port = '12345';
    //$url = 'http://www.domain.com';

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_PROXYPORT, $proxy_port);
    curl_setopt($ch, CURLOPT_PROXYTYPE, 'HTTP');
    curl_setopt($ch, CURLOPT_PROXY, $proxy_ip);
    curl_setopt($ch, CURLOPT_PROXYUSERPWD, $loginpassw);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}

? :idea:
$loginpassw = 'username:password'
CURLOPT_PROXYUSERPWD, $loginpassw
Тази опция какъв юзър и парола изисква? Немога да схвана какво трябва да въведа в нея смисъл става дума за прокси което има някаква парола ли какво?
 

Back
Горе