2015-10-03 9 views
10

Ho il seguente codice ma restituisce sempre un codice di stato HTTP 407.Come utilizzare l'autenticazione proxy con Goutte?

$url = 'http://whatismyip.org'; 

$client = new Client(); 

$options = array(
    'proxy' => array(
     'http' => 'tcp://@x.x.x.x:8010', 
    ), 
    'auth' => array('d80fe9ebasab73d21a4', '', 'basic') 
); 

$crawler = $client->request('GET', $url, $options); 

$status = $client->getResponse()->getStatus(); 

echo $status; // 407 

Sto usando Goutte con Guzzle 6. Ho iniziato cercando di impostare il proxy con setDefaultOption ma questo metodo è stato deprecato.

mio username e password vuota è sicuramente corretto in quanto funziona con curl sulla riga di comando:

curl -U d80fe9ebasab73d21a4: -vx x.x.x.x:8010 http://whatismyip.org/ 

Ho trascorso molte ore su questo e Gradirei qualsiasi aiuto!

+0

Ciò può accadere quando un client tenta di utilizzare HTTP1 anziché HTTP1.1 - curl_setopt ($ curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); Non sai come funziona il client all'interno .. controlla la tua versione arricciata – DannyZB

+0

Difficile dire. Utilizzare Wireshark per ispezionare la richiesta sul livello di rete. Controlla anche di aver abilitato l'estensione cURL nel tuo PHP e Guzzle usa CurlHandler. Perché hai '@' char prima del proxy IP? Puoi anche provare come indirizzo proxy qualcosa come questo 'http: //[email protected]: 8010' e omettere l'opzione' auth'. – kba

+0

@Abs: come hai risolto il problema del proxy. Puoi farmi sapere ? – 06011991

risposta

1

Hai provato a creare un'istanza del client con le opzioni proxy direttamente?

Ti piace questa:

$url = 'http://whatismyip.org'; 

$client = new Client($url, array(
    'version'  => 'v1.1', 
    'request.options' => array(
     'auth' => array('d80fe9ebasab73d21a4', '', 'Basic'), 
     'proxy' => 'tcp://@x.x.x.x:8010' 
    ) 
)); 


$crawler = $client->request('GET', $url); 

$status = $client->getResponse()->getStatus(); 

echo $status; // 407 
+0

Stucken: questa soluzione non funziona per me. restituisce il mio IP del sistema locale invece del proxy IP. puoi suggerire qualche soluzione per questo? – 06011991

1
$config = [ 
    'proxy' => [ 
     'http' => 'xx.xx.xx.xx:8080' 
    ] 
]; 

$client = new Client($config); 
$client->setAuth('username', 'password', 'basic'); 

$crawler = $client->request('GET', $url); 
$status = $client->getResponse()->getStatus(); 

echo $status; 

Suppongo che sia una configurazione client, non è un parametro di richiesta.

Problemi correlati