protected HttpWebRequest GetHttpWebRequest(webMethod method, string addr, string payload = null, string basicUserName = null, string basicPassword = null) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URLSparkCloud + addr); request.Timeout = webrequestTimeout; if (localProxy != null) { request.Proxy = localProxy; } if (basicUserName != null & basicPassword != null) { byte[] authBytes = Encoding.UTF8.GetBytes((basicUserName + ":" + basicPassword).ToCharArray()); request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes)); } request.Method = method.ToString(); if (method != webMethod.DELETE) { request.ContentType = contentType; request.ContentLength = 0; } if (!string.IsNullOrEmpty(payload) && method == webMethod.POST) { byte[] bytes = StringToUTF8Bytes(payload); request.ContentLength = bytes.Length; using (Stream writeStream = request.GetRequestStream()) { writeStream.Write(bytes, 0, bytes.Length); } } return(request); }
protected HttpWebRequest GetHttpWebRequest(webMethod method, string addr, string payload = null, string basicUserName = null, string basicPassword = null ) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(URLSparkCloud + addr); request.Timeout = webrequestTimeout; if (localProxy != null) { request.Proxy = localProxy; } if (basicUserName != null & basicPassword != null) { byte[] authBytes = Encoding.UTF8.GetBytes((basicUserName + ":" + basicPassword).ToCharArray()); request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(authBytes)); } request.Method = method.ToString(); if (method != webMethod.DELETE) { request.ContentType = contentType; request.ContentLength = 0; } if (!string.IsNullOrEmpty(payload) && method == webMethod.POST) { byte[] bytes = StringToUTF8Bytes(payload); request.ContentLength = bytes.Length; using (Stream writeStream = request.GetRequestStream()) { writeStream.Write(bytes, 0, bytes.Length); } } return request; }