asp.net 多参数请求
周祥·
2014-05-08·
1 次阅读
一般我用于 需要获取网页返回的内容时调用 比较方便强大 支持自定义多参数
public static string HttpRequst(string RequstUrl, Dictionary h = null, string Method = "GET", bool IsTz = false)
{
if (h != null)
{
foreach (var item in h)
{
RequstUrl += (RequstUrl.IndexOf("?") > -1 ? "&" : "?");
RequstUrl += item.Key + "=" + item.Value;
}
}
string responseData = null;
if (IsTz)
{
return RequstUrl;
}
HttpWebRequest webRequest = WebRequest.Create(RequstUrl) as HttpWebRequest;
webRequest.Method = Method;
webRequest.ServicePoint.Expect100Continue = false;
webRequest.Timeout = 10000000;
webRequest.ContentType = Content_Type;
//webRequest.KeepAlive = true;
StreamReader responseReader = null;
try
{
responseReader = new StreamReader(webRequest.GetResponse().GetResponseStream());
responseData = responseReader.ReadToEnd();
}
catch
{
}
finally
{
webRequest.GetResponse().GetResponseStream().Close();
responseReader.Close();
responseReader = null;
webRequest = null;
}
return responseData;
}调用例子:
Dictionary h = new Dictionary();
h.Add("response_type", "code");
h.Add("client_id", appid);
h.Add("redirect_uri", "http://www.decadework.com/");
h.Add("state", GetSha1(GetTimeStamp()));
return HttpRequst("https://graph.qq.com/oauth2.0/authorize", h, "GET", true).Trim();记录下 以后用 不需要到处找