Visualizzazione dei risultati da 1 a 5 su 5
  1. #1
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331

    problema passaggio parametri con cUrl

    Salve a tutti, ho questo script php

    Codice PHP:
    $locationStart $_GET['percorsiForm:originAddress'];
      
    $locationEnd $_GET['percorsiForm:destinationAddress'];
      
    $firma "prova";
      
    $calcola $_GET['percorsiForm:calcola'];
      
    $form 'percorsiForm';

      echo 
    "Location start = ".$locationStart."\n";
      echo 
    "Location end = ".$locationEnd."\n";
      echo 
    "Firma = ".$firma."\n";
      echo 
    "Calcola = ".$calcola."\n";
      echo 
    "Form = ".$form."\n";
      
      
    $url "http://163.162.91.62/prove/test.php"
      
    $post_fields "percorsiForm:originAddress=".$locationStart."&percorsiForm:originCity=Torino"."&percorsiForm:destinationAddress=".$locationEnd."&percorsiForm:destinationCity=Torino&percorsiForm:calcola=".$calcola."&com.sun.faces.VIEW=".$firma."&percorsiForm=".$form//form Fields.
      
      
    $ch curl_init();    // initialize curl handle
      
    curl_setopt($chCURLOPT_URL$url); // Pass URL as parameter.
      
    curl_setopt($chCURLOPT_GET1); // use this option to Post a form
      
    curl_setopt($chCURLOPT_GETFIELDS$post_fields); // Pass form Fields.
      
      
    curl_setopt($chCURLOPT_PROXYAUTHCURLAUTH_NTLM);

      
    curl_setopt($chCURLOPT_PROXYTYPECURLPROXY_HTTP);
      
    curl_setopt($chCURLOPT_PROXY"proxyURL"); 
      
    curl_setopt($chCURLOPT_PROXYPORTproxyPort); 
      
    curl_setopt($chCURLOPT_PROXYUSERPWD'user:'pwd);
      
      
    curl_setopt($chCURLOPT_RETURNTRANSFER1); // Return Page contents.
      
    $result curl_exec($ch); // grab URL and pass it to the variable.
      
    curl_close($ch); // close curl resource, and free up system resources.
      
    echo $result// Print page contents. 
    e in test.php (una pagina php di prova per vedere se i parametri vengono passati correttamente ho questo scrpt:

    Codice PHP:

     $locationStart 
    $_GET['percorsiForm:originAddress'];
     
    $locationEnd $_GET['percorsiForm:destinationAddress'];
     
    $firma $_GET['com.sun.faces.VIEW'];
     
    $calcola $_GET['percorsiForm:calcola'];
     
    $form $_GET['percorsiForm'];

     echo 
    "\n"." TEST PAGE"."\n";
     echo 
    "Location start = ".$locationStart."\n";
     echo 
    "Location end = ".$locationEnd."\n";
     echo 
    "Firma = ".$firma."\n";
     echo 
    "Calcola = ".$calcola."\n";
     echo 
    "Form = ".$form."\n"
    pero' i parametri risultano tutti NULL come se non venissero passati!
    Dove sbaglio?

    Ciao e grazie
    Sandro

  2. #2
    CURLOPT_GET e CURLOPT_GETFIELDS non esistono. Devi utilizzare CURLOPT_POST e CURLOPT_POSTFIELDS.

    Poi, nello script di test, devi utilizzare $_POST, non $_GET.

  3. #3
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331
    Ok, adesso nella pagina di test funziona.
    Io pero' dovrei usare cUrl per accedere ad una URL a cui prima accedevo mediante il method=get e non post nella form della jsp.
    Domanda per accedere a quella pagina devo usare le opzioni CURLOPT_POST e CURLOPT_POSTFIELDS o ce ne sono altre che emulano l'accesso con method=get?

  4. #4
    Per passare parametri tramite GET, li devi inserire nella querystring dell'URL.

  5. #5
    Utente di HTML.it
    Registrato dal
    Oct 2007
    Messaggi
    331
    Ho modificato lo script in questo modo:

    Codice PHP:

    $locationStart 
    $_GET['percorsiForm:originAddress'];
      
    $locationEnd $_GET['percorsiForm:destinationAddress'];
      
    $firma "prova";
      
    $calcola $_GET['percorsiForm:calcola'];
      
    $form "percorsiForm";

      echo 
    nl2br("Location start = ".$locationStart."\n");
      echo 
    nl2br("Location end = ".$locationEnd."\n");
      echo 
    nl2br("Firma = ".$firma."\n");
      echo 
    nl2br("Calcola = ".$calcola."\n");
      echo 
    nl2br("Form = ".$form."\n");
      
      
    $url "http://163.162.91.62/prove/test.php?originAddress=".$locationStart."&originCity=Torino&destinationAddress=".$locationEnd//."&destinationCity=Torino&calcola=".$calcola."&percorsiForm=".$form;  
      
      
    echo nl2br("url = ".$url."\n");
      echo 
    nl2br(" urlencoded = ".urlencode($url)."\n");
      
      
    $ch curl_init();    // initialize curl handle
      
    curl_setopt($chCURLOPT_URLurlencode($url)); // Pass URL as parameter.
      // curl_setopt($ch, CURLOPT_POST, 1); // use this option to Post a form
        
      
    curl_setopt($chCURLOPT_PROXYAUTHCURLAUTH_NTLM);
      
    curl_setopt($chCURLOPT_PROXYTYPECURLPROXY_HTTP);
      
    curl_setopt($chCURLOPT_PROXY"ipproxy"); 
      
    curl_setopt($chCURLOPT_PROXYPORTport); 
      
    curl_setopt($chCURLOPT_PROXYUSERPWD'user:pwd');
      
      
    curl_setopt($chCURLOPT_RETURNTRANSFER1); // Return Page contents.
      
    $result curl_exec($ch); // grab URL and pass it to the variable.
      
    curl_close($ch); // close curl resource, and free up system resources.
      
    echo $result// Print page contents. 
    ma quando eseguo il tutto sembra che il proxy mi dia un errore del tipo:

    Error Code: 502 Proxy Error. The parameter is incorrect. (87)

    Cosa puo' essere?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2024 vBulletin Solutions, Inc. All rights reserved.