HttpWebRequest请求那个地址获取返回的json数据然后前后截取或者建立json对应的类,用Newtonsoft.Json.Net20.dll序列化为你的类就可以访问了。
using System;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
public class HttpSend
{
/// <summary>
/// GET下载页面内容
/// </summary>
/// <param name="url">请求的地址</param>
/// <param name="encoding">内容编码</param>
/// <returns></returns>
public static string GetPageContent(string url, Encoding encoding)
{
string html=null;
try
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
request.Method = "GET";
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream ioStream = response.GetResponseStream();
StreamReader sr = new StreamReader(ioStream, encoding);
html = sr.ReadToEnd();
sr.Close();
ioStream.Close();
response.Close();
}
catch (Exception ex) { }
return html;
}
}
//使用
string html=HttpSend.GetPageContent("你的qq oauth地址",Encoding.UTF8);
string key = "\"openid\":\"";
int startIndex = html.IndexOf(key);
if (startIndex != -1)
{
int endIndex = html.IndexOf("\",", startIndex);
string openid = html.Substring(startIndex + key.Length, endIndex - startIndex - key.Length);
Response.Write(openid);
}
else
{//找不到openid,出错了。。
}