|
@@ -25,6 +25,12 @@ namespace ServiceCenter.WebApi
|
|
|
return JsonConvert.DeserializeObject<T>(result);
|
|
|
}
|
|
|
|
|
|
+ public static T CallApi1<T>(string url, string parameter, string type = "GET")
|
|
|
+ {
|
|
|
+ var result = HttpApi(url + parameter, "", type);
|
|
|
+ return JsonConvert.DeserializeObject<T>(result);
|
|
|
+ }
|
|
|
+
|
|
|
public static T CallApi<T>(string url, object parameter, string type = "Post")
|
|
|
{
|
|
|
var content = JsonConvert.SerializeObject(parameter);
|
|
@@ -91,11 +97,16 @@ namespace ServiceCenter.WebApi
|
|
|
request.Timeout = 60000;//连接超时
|
|
|
request.ReadWriteTimeout = 3600000;//读写超时
|
|
|
request.Accept = "text/html,application/xhtml+xml,*/*";
|
|
|
+
|
|
|
request.ContentType = "application/json";
|
|
|
request.Method = type.ToUpper().ToString();//get或者post
|
|
|
byte[] buffer = encoding.GetBytes(jsonstr);
|
|
|
request.ContentLength = buffer.Length;
|
|
|
- request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
|
|
+ if (type != "GET")
|
|
|
+ {
|
|
|
+ request.GetRequestStream().Write(buffer, 0, buffer.Length);
|
|
|
+ }
|
|
|
+
|
|
|
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
|
|
|
using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8))
|
|
|
{
|
|
@@ -112,4 +123,4 @@ namespace ServiceCenter.WebApi
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+}
|