看代码中对response的处理即可,
public class GetParam
{
public GetParam(string key, string value)
{
this.key = key;
this.value = value;
}
public string key {
get; set; }
public string value {
get; set; }
}
public static string RestfulGet(List<GetParam> getParams,string url)
{
StringBuilder urlBulder = new StringBuilder();
urlBulder.Append(url);
GetParam item;
if (getParams.Count>0)
{
item = getParams[0];
urlBulder.Append(item.key);
urlBulder.Append("=");
urlBulder.Append(item.value);
}
for (int i = 1; i < getParams.Count; i++)
{
item = getParams[i];
urlBulder.Append("&");
urlBulder.Append(item.key);
urlBulder.Append("=");
urlBulder.Append(item.value);
}
HttpWebRequest request = WebRequest.Create(urlBulder.ToString()) as HttpWebRequest;
request.Method = "GET";
string json = string.Empty;
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
Stream responseStream = responseStream = response.GetResponseStream();
if (response.ContentEncoding.ToLower().Contains("gzip"))
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
else if (response.ContentEncoding.ToLower().Contains("deflate"))
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
StreamReader reader = new StreamReader(responseStream, Encoding.UTF8);
json = reader.ReadToEnd();
}
return json;
}