Ciao, devo eseguire il login su un forum phpbb, e quindi accedere alle pagine con accesso ristretto.



Sono riuscito a trovare la stessa cosa ma in php:

Codice PHP:
function login($username$password)
    {
        global 
$_SERVER;
    
        
// Generate post string
        
$post_fields $this->array_to_http(array(
            
'username'    => $username,
            
'password'    => $password,
            
'autologin'    => 1,
            
'redirect'    => 'index.php',
            
'login'        => 'Log In',
        ));
        
// Init curl
        
$this->curl curl_init();
        
// Set options
        
curl_setopt $this->curlCURLOPT_URL$this->phpbb_url 'ucp.php?mode=login' ); 
        
curl_setopt $this->curlCURLOPT_POSTtrue );
        
curl_setopt $this->curlCURLOPT_POSTFIELDS$post_fields );
        
curl_setopt $this->curlCURLOPT_RETURNTRANSFERtrue );
        
curl_setopt $this->curlCURLOPT_HEADERfalse );
        
curl_setopt $this->curlCURLOPT_COOKIE$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_COOKIEJAR$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_COOKIEFILE$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT'] );
        
// Execute request
        
$result curl_exec $this->curl );
        
// Error handling
        
if ( curl_errno $this->curl ) )
        {
            
$this->error = array(
                
curl_errno($this->curl),
                
curl_error($this->curl),
            );
            
curl_close $this->curl );
            return 
false;
        }
        
// Close connection
        
curl_close $this->curl );
        
// Return result
        
return true;
    }

    
/*
        @ Function    : read() - Read a pages contents
        @ About        : Returns the contents of a url
        @ Type        : Public
    */
    
function read($page_url)
    {
        global 
$_SERVER;

        
// Init curl
        
$this->curl curl_init();
        
// Set options
        
curl_setopt $this->curlCURLOPT_URL$this->phpbb_url $page_url );
        
curl_setopt $this->curlCURLOPT_POSTfalse );
        
curl_setopt $this->curlCURLOPT_RETURNTRANSFERtrue );
        
curl_setopt $this->curlCURLOPT_HEADERfalse );
        
curl_setopt $this->curlCURLOPT_COOKIE$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_COOKIEJAR$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_COOKIEFILE$this->cookie_name );
        
curl_setopt $this->curlCURLOPT_USERAGENT$_SERVER['HTTP_USER_AGENT'] );
        
// Execute request
        
$result curl_exec $this->curl );
        
// Error handling
        
if ( curl_errno $this->curl ) )
        {
            
$this->error = array(
                
curl_errno($this->curl),
                
curl_error($this->curl),
            );
            
curl_close $this->curl );
            return 
false;
        }
        
// Close connection
        
curl_close $this->curl );
        
// Return result
        
return $result;
    } 

Mi servirebbe una traduzione php->C#.
L'importante è che dopo che ho fatto il login possa accedere alle pagine ristrette.


Grazie