public static string DoPost(string url, HttpParamers paramers, HttpHeader header, int connectTimeout, int readTimeout) { Stream requestStream = null; HttpWebRequest request = null; string responseAsString; try { request = HttpConnection.GetRequest(url, HttpMethod.POST, header); request.ReadWriteTimeout = readTimeout; request.Timeout = connectTimeout; if (paramers.IsMultipart()) { string boundary = "----sdkboundary" + StringUtils.Random(6); request.ContentType = CONTENT_MULTIPART + boundary; Stream stream2 = new MemoryStream(); WriteMutiContent(boundary, paramers, ref stream2); request.ContentLength = stream2.Length; stream2.Position = 0L; byte[] buffer = new byte[stream2.Length]; stream2.Read(buffer, 0, buffer.Length); stream2.Close(); requestStream = request.GetRequestStream(); requestStream.Write(buffer, 0, buffer.Length); requestStream.Close(); } else if (paramers.IsJsonApplication()) { string jsonParamer = paramers.JsonParamer; byte[] bytes = Encoding.UTF8.GetBytes(jsonParamer); request.ContentType = JSON_CONTENT_FORM; requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); } else { string queryString = paramers.GetQueryString(); if (!string.IsNullOrEmpty(queryString)) { byte[] bytes = Encoding.UTF8.GetBytes(queryString); request.ContentType = CONTENT_FORM; requestStream = request.GetRequestStream(); requestStream.Write(bytes, 0, bytes.Length); requestStream.Close(); } } responseAsString = GetResponseAsString(request); } catch (Exception exception1) { if (requestStream != null) { requestStream.Close(); } throw exception1; } return(responseAsString); }
public static void DoDownload(string url, HttpParamers paramers, HttpHeader header, int connectTimeout, int readTimeout, ref Stream stream) { try { string queryString = paramers.GetQueryString(); HttpWebRequest request = HttpConnection.GetRequest(BuildGetUrl(url, queryString), HttpMethod.GET, header); request.ReadWriteTimeout = readTimeout; request.Timeout = connectTimeout; GetResponseAsOutputStream(request, ref stream); } catch (Exception exception1) { throw exception1; } }
public static string DoGet(string url, HttpParamers paramers, HttpHeader header, int connectTimeout, int readTimeout) { string responseAsString; try { string queryString = paramers.GetQueryString(); HttpWebRequest request = HttpConnection.GetRequest(BuildGetUrl(url, queryString), HttpMethod.GET, header); request.ReadWriteTimeout = readTimeout; request.Timeout = connectTimeout; responseAsString = GetResponseAsString(request); } catch (Exception exception1) { throw exception1; } return(responseAsString); }