Can't match the C# code to the Unix command CURL is correct, responce is OK, but C# is {"data":null}
:
curl -k -d "username=test@pve&password=User11" https://ip:8006/api2/json/access/ticket
C#
string url = "https://ip:8006/api2/json/access/ticket";
WebRequest myReq = WebRequest.Create(url);
string username = "test@pve";
string password = "User11";
string usernamePassword = username + ":" + password;
CredentialCache mycache = new CredentialCache();
mycache.Add(new Uri(url), "Basic", new NetworkCredential(username, password));
myReq.Credentials = mycache;
myReq.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));
WebResponse wr = myReq.GetResponse();
Stream receiveStream = wr.GetResponseStream();
StreamReader reader = new StreamReader(receiveStream, Encoding.UTF8);
string content = reader.ReadToEnd();
Console.WriteLine(content);
Console.ReadLine();
Response:
{"data":null}