示例#1
0
        /// <summary>
        /// 请求
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        static Stream Request(HttpClientContent param)
        {
            var encoding = param.Encode;

            byte[] data    = encoding.GetBytes(param.Data);
            var    request = WebRequest.Create(param.Url) as HttpWebRequest;

            request.Method      = param.MethodType.ToString();
            request.ContentType = param.ContentType;
            if (param.Headers != null && param.Headers.Count > 0)
            {
                foreach (var item in param.Headers)
                {
                    request.Headers.Add(item.Key, item.Value);
                }
            }
            if (param.X509Certificate != null && param.X509Certificate.Count > 0)
            {
                request.ClientCertificates.AddRange(param.X509Certificate.ToArray());
            }
            if (param.MethodType == HttpMethodType.Post || param.MethodType == HttpMethodType.Put)
            {
                request.ContentLength = data.Length;
                using (var outstream = request.GetRequestStream())
                {
                    outstream.Write(data, 0, data.Length);
                }
            }
            var response = request.GetResponse() as HttpWebResponse;

            return(response.GetResponseStream());
        }
示例#2
0
 /// <summary>
 /// Put请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static string PutString(HttpClientContent param)
 {
     try
     {
         using (var s = new StreamReader(PutRequest(param), Encoding.UTF8))
         {
             return(s.ReadToEnd());
         }
     }
     catch (Exception ex)
     {
         return(ex.Message);
     }
 }
示例#3
0
 /// <summary>
 /// Delete请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static Stream DeleteStream(HttpClientContent param)
 {
     return(DeleteRequest(param));
 }
示例#4
0
 /// <summary>
 /// 异步Delete请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static async Task <byte[]> DeleteBytesAsync(HttpClientContent param)
 {
     return(await Task.Run(() => { return DeleteBytes(param); }));
 }
示例#5
0
 /// <summary>
 /// Delete请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static byte[] DeleteBytes(HttpClientContent param)
 {
     return(DeleteRequest(param).ToBytes());
 }
示例#6
0
 /// <summary>
 /// Delete请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 private static Stream DeleteRequest(HttpClientContent param)
 {
     param.MethodType = HttpMethodType.Delete;
     return(Request(param));
 }
示例#7
0
 /// <summary>
 /// 异步Put请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static async Task <string> PutStringAsync(HttpClientContent param)
 {
     return(await Task.Run(() => { return PutString(param); }));
 }
示例#8
0
 /// <summary>
 /// 异步Put请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static async Task <Stream> PutStreamAsync(HttpClientContent param)
 {
     return(await Task.Run(() => { return PutStream(param); }));
 }
示例#9
0
 /// <summary>
 /// Put请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static Stream PutStream(HttpClientContent param)
 {
     return(PutRequest(param));
 }
示例#10
0
 /// <summary>
 /// Put 请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static byte[] PutBytes(HttpClientContent param)
 {
     return(PutRequest(param).ToBytes());
 }
示例#11
0
 /// <summary>
 /// Put请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static Stream PutRequest(HttpClientContent param)
 {
     param.MethodType = HttpMethodType.Put;
     return(Request(param));
 }
示例#12
0
 /// <summary>
 /// Post 请求
 /// </summary>
 /// <param name="param"></param>
 /// <returns></returns>
 public static byte[] PostBytes(HttpClientContent param)
 {
     return(PostStream(param).ToBytes());
 }