0

I'm trying to get an authenication cookie from an website. I have managed to get this working with an tcl-script. The script looks like this:

proc get_cookie { connector_id } {
    global USER PASSWORD URL

    set post_url "[get_proxy_url $connector_id]/httpaccess.net/login"

    set post_data "user=[urlencode ${USER}]&password=[urlencode ${PASSWORD}]&url=[urlencode $URL]&serviceId=${connector_id}&token=12345"

    catch { 
        exec wget --post-data $post_data --no-check-certificate $post_url --max-redirect=0 -q -S -O - 2>@1
    } stderr

    if [string match "*HTTP/1.1 302 Found*" $stderr] {
        if [regexp {Location: *https://[0-9a-z\-.]+/httpaccess.net/([^/]+)/} $stderr dummy cookie] {
            return $cookie
        }
    }

    error "Error getting login cookie for $connector_id: $stderr"
}

Now I'm trying to get this to work in an c# application. But it is not working I'm only getting the html code of the homepage. My code looks like that now. What is the problem?

public MainWindow()
{
  InitializeComponent();

  string user = "man@gmail.de";
  string password = "xxxxxx";
  string url = "http://dev.net/testfiles/test_5kB.htm";
  string connectorId = "SDYYYYYYYHDMN354KS59";
  string post_data = string.Format("user={0}&password={1}&url={2}&serviceId={3}&token={4}", user, password, url, connectorId, "12345");

  var cli = new WebClient();
  var data = cli.UploadString("https://http.aa.net/xxx/httpaccess.net/login", post_data);
}
Donal Fellows
  • 133,037
  • 18
  • 149
  • 215
Kingpin
  • 1,067
  • 2
  • 14
  • 34
  • Do you need to url-encode the fields in the `post_data` in the C# version? – Donal Fellows Jan 06 '15 at 14:25
  • They are used in the tcl script and use the password and the username. – Kingpin Jan 06 '15 at 14:30
  • 1
    The WebClient class doesn't store cookies at default. http://stackoverflow.com/questions/1777221/using-cookiecontainer-with-webclient-class shows how to handle cookies. – John Jan 06 '15 at 15:46

0 Answers0