我只需要检索维基百科页面的第一段.内容必须是html格式化,随时可以在我的网站上显示(所以没有BBCODE或WIKIPEDIA特殊代码!)
这可能是一个非常简单的问题,但我似乎无法格式化web webrequest /响应以从Wikipedia API获取数据.我已经在下面发布了我的代码,如果有人可以帮我看看我的问题.
string pgTitle = txtPageTitle.Text;
Uri address = new Uri("http://en.wikipedia.org/w/api.php");
HttpWebRequest request = WebRequest.Create(address) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
string action = "query";
string query = pgTitle;
StringBuilder data = new StringBuilder();
data.Append("action=" + HttpUtility.UrlEncode(action));
data.Append("&query=" + HttpUtility.UrlEncode(query));
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data.ToString());
request.ContentLength = byteData.Length;
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream.
StreamReader reader = new …Run Code Online (Sandbox Code Playgroud)