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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| String credentials = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(user + ":" + pwd));
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls;
string url;
if (pQueryType == QueryType.post)
{
url = string.Format("https://{0}//putxml", ipAddress);
}
else
{
url = string.Format("https://{0}/getxml?{1}", ipAddress, pQuery);
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Headers.Add("Authorization", "Basic " + credentials);
request.UserAgent= "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:25.0) Gecko/20100101 Firefox/25.0";
request.Method = pQueryType == QueryType.post ? "POST" : "GET";
byte[] bytes;
if (pQueryType == QueryType.post)
{
bytes = System.Text.Encoding.UTF8.GetBytes(pQuery);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = bytes.Length;
request.Timeout = 3000;
request.ProtocolVersion = HttpVersion.Version11;
request.KeepAlive = false;
request.Accept = "*/*";
if (request.Proxy != null)
{
request.Proxy.Credentials = CredentialCache.DefaultCredentials;
}
request.AllowWriteStreamBuffering = false;
request.Credentials = CredentialCache.DefaultCredentials;
Stream requestStream = request.GetRequestStream(); // <<<ECHEC ICI
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
string responseStr = new StreamReader(responseStream).ReadToEnd();
result = true;
pResponse = responseStr;
responseStream.Close();
} |
Partager