| | |
| | | } |
| | | |
| | | } |
| | | public string Put(string url, string putData, string contentType = "application/json", string sessionId = "") |
| | | { |
| | | Console.WriteLine(url); |
| | | WebRequest request = WebRequest.Create(url); |
| | | request.Method = "PUT"; |
| | | byte[] byteArray = Encoding.UTF8.GetBytes(putData); |
| | | request.ContentType = contentType; |
| | | request.ContentLength = byteArray.Length; |
| | | request.Timeout = 3000; |
| | | if (sessionId != "") |
| | | { |
| | | request.Headers.Set("ASP.NET_SessionId", sessionId); |
| | | } |
| | | StreamReader reader = null; |
| | | Stream stream = null; |
| | | WebResponse rsp = null; |
| | | try |
| | | { |
| | | stream = request.GetRequestStream(); |
| | | stream.Write(byteArray, 0, byteArray.Length); |
| | | stream.Close(); |
| | | rsp = request.GetResponse(); |
| | | stream = rsp.GetResponseStream(); |
| | | reader = new StreamReader(stream); |
| | | return reader.ReadToEnd(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Console.WriteLine($"{url} err={ex.Message}"); |
| | | return ""; |
| | | } |
| | | finally |
| | | { |
| | | // 释放资源 |
| | | if (reader != null) reader.Close(); |
| | | if (stream != null) stream.Close(); |
| | | if (rsp != null) rsp.Close(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | public string Post(string url, Dictionary<string, string> dic) { |