如何使用Web请求/ Web响应?

时间:2014-05-27 13:34:37

标签: c# asp.net httpwebrequest pinterest

通过使用网络请求/响应类,我想尝试登录Pinterest网站..但我无法做到这一点,因为它给了我' csrf错误'。

以下是我的代码。

WebRequest request = WebRequest.Create("https://www.pinterest.com/login");
request.Credentials = new NetworkCredential("myid", "mypassword");
request.Method = "POST";
string postData = "This is a test that posts this string to a Web server.";
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
Console.WriteLine(((HttpWebResponse)response).StatusDescription);
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
Console.WriteLine(responseFromServer);
Console.ReadLine();
reader.Close();
dataStream.Close();
response.Close();

我在这里做错了什么?

0 个答案:

没有答案