#region Service
///
/// Get Serveic
///
/// URL
/// paramter
protected string Service(string endPoint, Dictionary
{
//格式化参数
string populatedEndPoint = CreateFormattedPostRequest(paramters);
//创建HttpWebRequest对象
HttpWebRequest req = CreateWebRequest(endPoint + populatedEndPoint, StringUtil.GetStringByte(populatedEndPoint).Length);
//取得返回值
HttpWebResponse resp = req.GetResponse() as HttpWebResponse;
Stream stream = resp.GetResponseStream();
string contents = string.Empty;
using (StreamReader reader = new StreamReader(stream, Encoding.UTF8))
{
contents = reader.ReadToEnd();
}
resp.Close();
stream.Close();
stream.Dispose();
req = null;
//取得内容Substring方法使用
contents = StringUtil.GetResponseBodyString(HttpUtility.UrlDecode(contents));
return contents;
}
#endregion
#region CreateFormattedPostRequest
///
///
///
///
///
private string CreateFormattedPostRequest(Dictionary
{
var paramterBuilder = new StringBuilder();
var counter = 0;
foreach (var value in values)
{
//paramterBuilder.AppendFormat("{0}={1}", value.Key, HttpUtility.UrlEncode(value.Value, Encoding.UTF8));
paramterBuilder.AppendFormat("{0}", value.Value);
if (counter != values.Count - 1)
{
paramterBuilder.Append("&");
}
counter++;
}
return paramterBuilder.ToString();
}
#endregion
您可以试试使用springboot来做这个需求
可以看看moob