I'm write here because I was trying to send a POST request to a server api,
I tried to send also another request(the first one) and from the response it work({"success":"true", "role":"USER"}
). But in the sencond request as a response I get: {"timestamp":1524589409895,"status":403,"error":"Forbidden","message":"Invalid CSRF Token 'null' was found on the request parameter '_csrf' or header 'X-XSRF-TOKEN'.","path":"/api/v1/rec"}
.
So I put all the cookies but one of them "XSRF -TOKEN" cause my program to crashSystem.Net.CookieException: The 'Name'='XSRF -TOKEN' part of the cookie is invalid
so I discovered that this cookie change every time you create a session
so I tried to get the cookies from the response of the first message and added on the header for the second one, and this is the result
I also set the NETFramework at the 4.5 version
I'm leaving a temporary account here for you so you can try this without creating an account only for a test
Request Payload from firefox
static void Main(string[] args)
{
Uri uri = new Uri("https://www.vcast.it/api/v1/rec");
cookieContainer = new CookieContainer();
cookieContainer.Add(uri, new Cookie("CONSENT", "true"));
cookieContainer.Add(uri, new Cookie("_ga", "GA1.2.940742918.1524584758"));
cookieContainer.Add(uri, new Cookie("_gid", "GA1.2.1691132054.1524584758"));
cookieContainer.Add(uri, new Cookie("remember-me", "Z1hvUnJoOHdIM3dCZ2pmYXVKamFRUT09OkpxSXUzRDVRUXd6UG14eGlVUlJMOXc9PQ"));
clienthandler = new HttpClientHandler { AllowAutoRedirect = true, UseCookies = true, CookieContainer = cookieContainer };
client = new HttpClient(clienthandler);
client.DefaultRequestHeaders.Host = "www.vcast.it";
MainAsync();
}
private static CookieContainer cookieContainer;
private static HttpClientHandler clienthandler;
private static HttpClient client;
static async void MainAsync()
{
Uri uri = new Uri("https://www.vcast.it");
var values = new Dictionary<string, string>
{
{ "username", "XXXX" },
{ "password", "XXXX" },
{ "remember-me", "undefined" },
{ "submit", "" }
};
var content = new FormUrlEncodedContent(values);
HttpResponseMessage response = await client.PostAsync("https://www.vcast.it/apiLogin?appId=58aef0c4ea5d52b2c0e4f2ed", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
Console.WriteLine("New Cookies:");
var responseCookies = cookieContainer.GetCookies(uri).Cast<Cookie>();
foreach (var cook in responseCookies)
{
cookieContainer.Add(uri, cook);
Console.WriteLine(cook.Name + ":" + cook.Value);
}
Console.WriteLine();
clienthandler = new HttpClientHandler { UseCookies = true, CookieContainer = cookieContainer };
client = new HttpClient(clienthandler);
values = JsonConvert.DeserializeObject<Dictionary<string, string>>("{\"name\":\"Titolo registrazione\",\"fromSuggestion\":false,\"manual\":true,\"followSeries\":false,\"resolution\":\"r576\",\"format\":\"MP4\",\"defaultProvider\":\"vcloud\",\"provider\":\"vcloud\",\"channelId\":\"58138235c9e77c00018242ed\",\"startDate\":1524585300000,\"endDate\":1524588900000,\"startHour\":17,\"startMinute\":55,\"endHour\":18,\"endMinute\":55}");
content = new FormUrlEncodedContent(values);
client.DefaultRequestHeaders.Referrer = new Uri("https://www.vcast.it/manualRec/");
response = await client.PostAsync("https://www.vcast.it/api/v1/rec", content);
Console.WriteLine(await response.Content.ReadAsStringAsync());
}
I will gladly accept any kind of comment or answer