public CallRet CallWithBinary(string url, string contentType, Stream body, long length) { Console.WriteLine("Client.PostWithBinary ==> URL: {0} Length:{1}", url, length); try { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = contentType; request.ContentLength = length; SetAuth(request, body); using (Stream requestStream = request.GetRequestStream()) { StreamUtil.CopyN(body, requestStream, length); } using (HttpWebResponse response = request.GetResponse() as HttpWebResponse) { return(HandleResult(response)); } } catch (Exception e) { Console.WriteLine(e.ToString()); return(new CallRet(HttpStatusCode.BadRequest, e)); } }