C# 以编程方式使用WebRequest登录Instagram 问题
我想将登录请求发送到Instagram服务器,以用户身份登录,但不知道如何登录C# 以编程方式使用WebRequest登录Instagram 问题,c#,http,authentication,https,request,C#,Http,Authentication,Https,Request,我想将登录请求发送到Instagram服务器,以用户身份登录,但不知道如何登录 源代码 这将不起作用,因为各种原因: Instagram使用Crsf代币,您在发出post请求时不会发送该代币。在您也不使用的其他标题中 第二个原因也是最重要的一个原因,即发送到instagram的POST请求中的参数是4(用户名、密码、查询参数、OptintOneTap)。虽然您可以使用用户名、查询参数和optionOneTap。你不能(你可以,但确实很难做到),将你的密码转换为他们正在制作的enc_密码。实现
源代码
这将不起作用,因为各种原因:
User-Agent
、Referer
、x-csrftoken
等
但是,如果您希望采用API路线,您可能希望按照中的建议实现Facebook登录
using System;
namespace WebRequests
{
public class Program
{
static void Main(string[] args)
{
System.Net.CookieContainer myCookies = new System.Net.CookieContainer();
Console.Write("Enter the username: ");
string username = Console.ReadLine();
Console.Write("Enter the password: ");
string password = Console.ReadLine();
string postData = "username=" + username + "&password=" + password + "&security_level=0&form=submit";
bool result = HttpMethods.Post("https://instagram.com/", postData, "https://instagram.com", myCookies);
if (result)
Console.WriteLine("Valid!");
else
Console.WriteLine("Invalid!");
}
}
}