Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';t使用httpwebrequest发布到https_C#_Https_Httpwebrequest - Fatal编程技术网

C# Can';t使用httpwebrequest发布到https

C# Can';t使用httpwebrequest发布到https,c#,https,httpwebrequest,C#,Https,Httpwebrequest,我正试图利用我们网站某个部分已经完成的功能,登录该网站,然后像使用浏览器一样与之交互。也许有一个更好的方法,所以这是值得欢迎的。不过,我不得不使用C# 此表单在其他空白网页中成功登录到网站(当然,我将其虚拟化): 我也试过: string URI = "https://myaccount.boom.us/Admin/Account/Login"; string postData = "EmailAddress=theprocess@oursite.com

我正试图利用我们网站某个部分已经完成的功能,登录该网站,然后像使用浏览器一样与之交互。也许有一个更好的方法,所以这是值得欢迎的。不过,我不得不使用C#

此表单在其他空白网页中成功登录到网站(当然,我将其虚拟化):

我也试过:

        string URI = "https://myaccount.boom.us/Admin/Account/Login";
            string postData = "EmailAddress=theprocess@oursite.com";
            postData += "&Password=avalidpassword";

        using (WebClient wc = new WebClient())
        {
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string HtmlResult = wc.UploadString(URI, postData);
        }
它也只是重新加载相同的登录页面


我做错了什么?

最好的调试方法是使用Fiddler之类的工具,通过浏览器登录您的站点。检查发送到服务器的请求,并将其与您在代码中发送的请求进行比较,看看缺少什么。我尝试了fiddler,但它没有提供任何有用的信息。或者也许我不够熟练,无法从fiddler那里提取有用的信息。
             var request = (HttpWebRequest)WebRequest.Create("https://oursite.com/Admin/Account/Login");

            string postData = "EmailAddress=theprocess@oursite.com";
            postData += "&Password=avalidpassword";
            byte[] data = Encoding.ASCII.GetBytes(postData);


            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = data.Length;

            using (var stream = request.GetRequestStream())
            {
                stream.Write(data, 0, data.Length);
            }

            var response = (HttpWebResponse)request.GetResponse();


            var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
        string URI = "https://myaccount.boom.us/Admin/Account/Login";
            string postData = "EmailAddress=theprocess@oursite.com";
            postData += "&Password=avalidpassword";

        using (WebClient wc = new WebClient())
        {
            wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
            string HtmlResult = wc.UploadString(URI, postData);
        }