Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/323.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# 使用Webrequest登录Amazon_C#_Login_Httpwebrequest_Amazon - Fatal编程技术网

C# 使用Webrequest登录Amazon

C# 使用Webrequest登录Amazon,c#,login,httpwebrequest,amazon,C#,Login,Httpwebrequest,Amazon,因此,我正在为自己制作一个个人程序,之前我在上面做了一个线程,在这个线程中,我制作了一个亚马逊最新商品检查器,在那里我可以提取所有购买的商品,并将它们填充到表单上的列表视图中 到目前为止,我一直在使用webbrowser,但这种方法需要很长时间。所以我想我应该尝试一下webrequests,这样做,我一直在尝试,但是我不能复制POST请求来登录 这是我的密码: var request = (HttpWebRequest)WebRequest.Create("https://www.amazon.

因此,我正在为自己制作一个个人程序,之前我在上面做了一个线程,在这个线程中,我制作了一个亚马逊最新商品检查器,在那里我可以提取所有购买的商品,并将它们填充到表单上的列表视图中

到目前为止,我一直在使用webbrowser,但这种方法需要很长时间。所以我想我应该尝试一下webrequests,这样做,我一直在尝试,但是我不能复制POST请求来登录

这是我的密码:

var request = (HttpWebRequest)WebRequest.Create("https://www.amazon.com/ap/signin?_encoding=UTF8&openid.assoc_handle=usflex&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.mode=checkid_setup&openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.ns.pape=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Fpape%2F1.0&openid.pape.max_auth_age=0&openid.return_to=https%3A%2F%2Fwww.amazon.com%2Fgp%2Fyourstore%2Fhome%3Fie%3DUTF8%26ref_%3Dgno_signin");

    var postData = "All this data is so long, there's no point of posting it";
    var 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();
    File.WriteAllText(@"C:\Users\Admin\Desktop\Source.html", responseString);

正如你所看到的,我正在输出源代码以检查它是否登录,但它总是直接返回登录页面,有人有什么想法吗?非常感谢各位。

首先,您需要发出get请求以检索此令牌,并保存所有cookie,然后随post请求一起发送。可能还有很多其他的安全措施——网站不喜欢你这样做,所以他们很难做到,我确信这一点;好的,我先试着抓住那个令牌。谢谢你,可能是2011年投票率最高的答案的翻版,但现在已经不行了。另请参见-其中指出了amzon登录页面上的javascript的功能。