小编sim*_*nye的帖子

无效的Uri:uri方案无效

我正在尝试通过WebRequest登录到网站。在这一点上,我得到一个例外:

WebRequest req = WebRequest.Create(formUrl.Trim());
Run Code Online (Sandbox Code Playgroud)

string url,string username,string password来自文本框。这是完整的代码:

public void LoginToUrl(string url,string username, string password )
{
    formUrl = url;
    formParams = string.Format("username={0}&password={1}", username,password);                  

    WebRequest req = WebRequest.Create(formUrl.Trim());//
    req.ContentType = "application/x-www-form-urlencoded";
    req.Method = "POST";
      bytes = Encoding.ASCII.GetBytes(formParams);
    req.ContentLength = bytes.Length;
    using (Stream os = req.GetRequestStream())
    {
        os.Write(bytes, 0, bytes.Length);
    }
    WebResponse resp = req.GetResponse();
    cookieHeader = resp.Headers["Set-cookie"];
}
Run Code Online (Sandbox Code Playgroud)

这是POST数据:

Host=internetlogin1.cu.edu.ng

User-Agent=Mozilla/5.0 (Windows NT 10.0; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0

Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language=en-US,en;q=0.5

Accept-Encoding=gzip, deflate
Run Code Online (Sandbox Code Playgroud)

引用此链接

Connection=keep-alive

Content-Type=application/x-www-form-urlencoded

Content-Length=49
POSTDATA=dst=&popup=true&username=13ck015373&password=F3NB
Run Code Online (Sandbox Code Playgroud)

c# asp.net

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

asp.net ×1

c# ×1