1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
|
static void Main(string[] args)
{
ServicePointManager.CertificatePolicy = new Program();
StringBuilder xml = new StringBuilder();
xml.Append("<?xml version=\"1.0\" encoding=\"utf-8\" ?>");
xml.Append("<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\">");
xml.Append("<soap:Header>");
xml.Append("<context xmlns=\"urn:zimbra\">");
xml.Append("<format type=\"xml\"/>");
xml.Append("</context>");
xml.Append("</soap:Header>");
xml.Append("<soap:Body>");
xml.Append("<AuthRequest xmlns=\"urn:zimbraAdmin\">");
xml.Append("<account by=\"name\">compte@exemple.fr</account>");
xml.Append("<password>motdepasse</password>");
xml.Append("</AuthRequest>");
xml.Append("</soap:Body>");
xml.Append("</soap:Envelope>");
Console.WriteLine(xml);
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(" https://serveurzimbra:port/service/admin/soap");
httpRequest.ContentType = "application/soap+xml";
byte[] byteArray = Encoding.UTF8.GetBytes(xml.ToString());
httpRequest.Method = "POST";
httpRequest.ContentLength = byteArray.Length;
using (var stream = httpRequest.GetRequestStream())
{
stream.Write(byteArray, 0, byteArray.Length);
}
var response = (HttpWebResponse)httpRequest.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
Console.ReadLine();
} |
Partager