在Universal App中登录WebSite不起作用

时间:2016-07-20 10:12:25

标签: c# universal

我有这段代码:

public async Task<string> getData()
    {
        ASCIIEncoding encoding = new ASCIIEncoding();
        string postData = string.Format("school={0}&username={1}&password={2}", "schoolcode", "username", "password");
        byte[] data = encoding.GetBytes(postData);

        WebRequest request = WebRequest.Create("https://example.com/login");
        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        request.Headers["ContentLength"] = data.Length.ToString();
        Stream stream = await request.GetRequestStreamAsync();
        stream.Write(data, 0, data.Length);
        WebResponse response = await request.GetResponseAsync();
        stream = response.GetResponseStream();
        StreamReader sr = new StreamReader(stream);
        string res = await sr.ReadToEndAsync();
        return res;
    }

当我执行代码时,它保持在线:

Stream stream = await request.GetRequestStreamAsync();

永远,它不起作用,我试过这个例子here但对我来说它不起作用,有谁知道为什么?谢谢;)

我还尝试使用www.google.com更改网址,但它既不起作用也不行。我没有任何代理人。

0 个答案:

没有答案