After logging in I can have a token from my remote system. For example the authentication_token is 8JySqFVx_pKx_3nx67AJ I can log out from terminal via this command
curl -v -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE https://sample.com\?authentication_token\=8JySqFVx_pKx_3nx67AJ
I need to do it from C#. I can send POST request like this:
WebClient wc = new WebClient();
string baseSiteString = wc.DownloadString("https://sample.com");
string csrfToken = Regex.Match(baseSiteString, "<meta name=\"csrf-token\" content=\"(.*?)\" />").Groups[1].Value;
string cookie = wc.ResponseHeaders[HttpResponseHeader.SetCookie];
wc.Headers.Add(HttpRequestHeader.Cookie, cookie);
wc.Headers.Add(HttpRequestHeader.ContentType, "application/json; charset=utf-8");
wc.Headers.Add(HttpRequestHeader.Accept, "application/json, text/javascript, */*; q=0.01");
wc.Headers.Add("X-CSRF-Token", csrfToken);
wc.Headers.Add("X-Requested-With", "XMLHttpRequest");
string dataString = @"{""user"":{""email"":""[email protected]"",""password"":""sample_password""}}";
byte[] dataBytes = Encoding.UTF8.GetBytes(dataString);
byte[] responseBytes = wc.UploadData(new Uri("https://sample.com/auth.json"), "POST", dataBytes);
string responseString = Encoding.UTF8.GetString(responseBytes);
How Can I send DELETE request from C# where authentication_token would be a parameter?
HttpClientclass, see asp.net/web-api/overview/advanced/… for samples