从WebClient获取身份验证cookie

时间:2015-01-06 13:47:57

标签: c# authentication cookies tcl webclient

我试图从网站上获取身份验证Cookie。我已经设法使用tcl脚本。脚本如下所示:

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"
}

现在我试图让它在c#应用程序中运行。但它不起作用我只获得主页的HTML代码。我的代码现在看起来像那样。有什么问题?

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);
}

0 个答案:

没有答案