I am sending a mail request in api with C # webrequest and httpClient, but always get an error message from api saying that you have placed invalid data in the header, but the fact is that I am sending the same data with the chrome extension client for recreation, it works fine, and I compared both requests: there is nothing else that I attached both the request and my code, can someone help figure out what the problem is,
This is a request from the client application for rest:

and here is a request from C #

and here is my c # code
string item = "<?xml version=\"1.0\" encoding=\"UTF - 8\"?>" +
"<request>" +
"<Username>admin</Username>" +
"<Password>" + password + "</Password>" +
"<password_type>4</password_type>" +
"</request> ";
var request = (HttpWebRequest)WebRequest.Create("http://192.168.8.1/api/user/login");
request.Method = "POST";
request.Headers["_RequestVerificationToken"]= Token;
request.Headers["Cookie"] = Sess;
byte[] bytes = Encoding.UTF8.GetBytes(item);
request.ContentType = "application/xml;charset=UTF-8";
request.ContentLength = bytes.Length;
Stream streamreq = request.GetRequestStream();
streamreq.Write(bytes, 0, bytes.Length);
streamreq.Close();
using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
using (StreamReader reader = new StreamReader(response.GetResponseStream()))
{
var result = reader.ReadToEnd();
}
source
share