|
@@ -65,123 +65,6 @@ namespace MySystem
|
|
return result;
|
|
return result;
|
|
}
|
|
}
|
|
|
|
|
|
-<<<<<<< HEAD
|
|
|
|
- #region 上传图片接口
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public string DoPost(string url, string token, IDictionary<string, string> textParams, IDictionary<string, FileItem> fileParams, string charset = "utf-8")
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- if (fileParams == null || fileParams.Count == 0)
|
|
|
|
- {
|
|
|
|
- return "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- string boundary = DateTime.Now.Ticks.ToString("X");
|
|
|
|
-
|
|
|
|
- HttpWebRequest req = GetWebRequest(url, "POST");
|
|
|
|
- req.Headers.Add("X-File-Token", token);
|
|
|
|
- req.ContentType = "multipart/form-data;charset=" + charset + ";boundary=" + boundary;
|
|
|
|
-
|
|
|
|
- Stream reqStream = req.GetRequestStream();
|
|
|
|
- byte[] itemBoundaryBytes = Encoding.GetEncoding(charset).GetBytes("\r\n--" + boundary + "\r\n");
|
|
|
|
- byte[] endBoundaryBytes = Encoding.GetEncoding(charset).GetBytes("\r\n--" + boundary + "--\r\n");
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- string textTemplate = "Content-Disposition:form-data;name=\"{0}\"\r\nContent-Type:text/plain\r\n\r\n{1}";
|
|
|
|
- IEnumerator<KeyValuePair<string, string>> textEnum = textParams.GetEnumerator();
|
|
|
|
- while (textEnum.MoveNext())
|
|
|
|
- {
|
|
|
|
- string textEntry = string.Format(textTemplate, textEnum.Current.Key, textEnum.Current.Value);
|
|
|
|
- byte[] itemBytes = Encoding.GetEncoding(charset).GetBytes(textEntry);
|
|
|
|
- reqStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
|
|
|
|
- reqStream.Write(itemBytes, 0, itemBytes.Length);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- string fileTemplate = "Content-Disposition:form-data;name=\"{0}\";filename=\"{1}\"\r\nContent-Type:{2}\r\n\r\n";
|
|
|
|
- IEnumerator<KeyValuePair<string, FileItem>> fileEnum = fileParams.GetEnumerator();
|
|
|
|
- while (fileEnum.MoveNext())
|
|
|
|
- {
|
|
|
|
- string key = fileEnum.Current.Key;
|
|
|
|
- FileItem fileItem = fileEnum.Current.Value;
|
|
|
|
- string fileEntry = string.Format(fileTemplate, key, fileItem.GetFileName(), fileItem.GetMimeType());
|
|
|
|
- byte[] itemBytes = Encoding.GetEncoding(charset).GetBytes(fileEntry);
|
|
|
|
- reqStream.Write(itemBoundaryBytes, 0, itemBoundaryBytes.Length);
|
|
|
|
- reqStream.Write(itemBytes, 0, itemBytes.Length);
|
|
|
|
-
|
|
|
|
- byte[] fileBytes = fileItem.GetContent();
|
|
|
|
- reqStream.Write(fileBytes, 0, fileBytes.Length);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- reqStream.Write(endBoundaryBytes, 0, endBoundaryBytes.Length);
|
|
|
|
- reqStream.Close();
|
|
|
|
-
|
|
|
|
- HttpWebResponse rsp = (HttpWebResponse)req.GetResponse();
|
|
|
|
- Encoding encoding = Encoding.GetEncoding(rsp.CharacterSet);
|
|
|
|
- return GetResponseAsString(rsp, encoding);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- public HttpWebRequest GetWebRequest(string url, string method)
|
|
|
|
- {
|
|
|
|
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
|
|
|
|
- req.ServicePoint.Expect100Continue = false;
|
|
|
|
- req.Method = method;
|
|
|
|
- req.KeepAlive = true;
|
|
|
|
- req.Timeout = 100000;
|
|
|
|
- return req;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- public string GetResponseAsString(HttpWebResponse rsp, Encoding encoding)
|
|
|
|
- {
|
|
|
|
- StringBuilder result = new StringBuilder();
|
|
|
|
- Stream stream = null;
|
|
|
|
- StreamReader reader = null;
|
|
|
|
-
|
|
|
|
- try
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- stream = rsp.GetResponseStream();
|
|
|
|
- reader = new StreamReader(stream, encoding);
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- int ch = -1;
|
|
|
|
- while ((ch = reader.Read()) > -1)
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- char c = (char)ch;
|
|
|
|
- if (c != '\0')
|
|
|
|
- {
|
|
|
|
- result.Append(c);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- finally
|
|
|
|
- {
|
|
|
|
-
|
|
|
|
- if (reader != null) reader.Close();
|
|
|
|
- if (stream != null) stream.Close();
|
|
|
|
- if (rsp != null) rsp.Close();
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return result.ToString();
|
|
|
|
- }
|
|
|
|
- #endregion
|
|
|
|
-
|
|
|
|
- public Dictionary<string, string> GetHeader(Dictionary<string, object> reqdic)
|
|
|
|
-=======
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@@ -720,7 +603,6 @@ namespace MySystem
|
|
}
|
|
}
|
|
|
|
|
|
public Dictionary<string, string> GetHeader(string req)
|
|
public Dictionary<string, string> GetHeader(string req)
|
|
->>>>>>> DuGuYang
|
|
|
|
{
|
|
{
|
|
Dictionary<string, string> headdic = new Dictionary<string, string>();
|
|
Dictionary<string, string> headdic = new Dictionary<string, string>();
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|
|
string timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
|