c# - Using WebClient to login to Pinterest (403 Error) -
so i'm trying login pinterest using webclient in asp.net page. cookiewebawareclient using:
public class cookieawarewebclient : webclient { public cookieawarewebclient() : this(new cookiecontainer()) { } public cookieawarewebclient(cookiecontainer c) { this.cookiecontainer = c; this.headers.add("user-agent: mozilla/5.0 (windows nt 6.1) applewebkit/536.5 (khtml, gecko) chrome/19.0.1084.52 safari/536.5"); } public cookiecontainer cookiecontainer { get; set; } protected override webrequest getwebrequest(uri address) { webrequest request = base.getwebrequest(address); if (request httpwebrequest) { (request httpwebrequest).cookiecontainer = this.cookiecontainer; } homecoming request; } }
here code using login, first doing request csrf token , other _ch value use.
var client = new cookieawarewebclient(); client.encoding = encoding.utf8; string html = client.downloadstring("https://pinterest.com/login/"); string csrftoken = getcsrftoken(html); string chtoken = getchtoken(html); var values = new namevaluecollection(); values.add("email", httputility.urlencode(my_email)); values.add("password",my_password); values.add("csrfmiddlewaretoken", csrftoken); values.add("_ch", chtoken); // 403 error happens below client.uploadvalues("https://pinterest.com/login/?next=%2flogin%2f", values); html = client.downloadstring("http://pinterest.com/settings");
i sense i'm missing little can't determine is.
c# webclient http-status-code-403
No comments:
Post a Comment