标签:
引用Dll:Newtonsoft.Json.dll
1.创建Url
Url组成 主机名 端口号 路径 参数
string strUrl = "http://192.199.101.101:9081/"+ string.Format("/Collect/GetProcessData?sessionId={0}&lineNo={1}", "123", "", "32");
2.创建Web请求并设置参数(http://www.cnblogs.com/armyfai/p/3889980.html)
HttpWebRequest request = WebRequest.Create(strUrl) as HttpWebRequest;
request.Method = "GET";
request.UserAgent = "Mozilla/4.0";
request.CookieContainer = cookie;
request.KeepAlive = true;
request.Timeout = 1000;
3.获取Jsion数据并转换为Hashtable
//获取服务器返回的资源
response = (HttpWebResponse)request.GetResponse()
//将请求返回内容转换为StreamReader
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8)
//将StreamReader转换为String
String jsonText = reader.ReadToEnd();
//将string转换为Hashtable
Hashtable hstJsonText= JsonConvert.DeserializeObject(jsonText, typeof(Hashtable)) as Hashtable;
标签:
原文地址:http://www.cnblogs.com/lhlong/p/4838970.html