Hi guys,
I would be very grateful if someone could give me an indication of how to build
up the request to the API. Just for a simple page query. I have some code that
uses Web request/response which works with other API's but it does not work
with the mediawiki api. I would be verya grateful if anyone could help me out.
I one of the methods I have tried below:
I consistenly get a "The remote server returned an error: (417) Expectation
failed." Error.
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
StreamReader(response.GetResponseStream());
divWikiData.InnerText = reader.ReadToEnd();
}
Spatial Analysis Unit
UNEP-WCMC
219 Huntingdon Road
Cambridge
CB3 0DL
Tel: +44 1223 277 314 xtn 225
________________________________
** Confidentiality Statement and Disclaimer **
This e-mail, together with any attachments, may contain confidential
information and/or copyright material. Any views or opinions presented are
solely those of the author and do not necessarily represent those of UNEP-WCMC.
It is intended only for the person named above. Any copying, distribution,
dissemination, disclosure or use of this message or its contents unless
authorised by us is strictly prohibited. If you have received this message in
error, please notify us immediately.
You should understand and accept that email communication with UNEP-WCMC is not
a totally secure communications medium. Although we have taken steps to ensure
that this e-mail and attachments are free from any virus, we cannot guarantee
that they are virus free. We do not, to the extent permitted by law, accept any
liability (whether in contract, negligence or otherwise) for any virus
infection and/or external compromise of security and/or breach of
confidentiality in relation to transmissions sent by e-mail. Thank you.
_______________________________________________
MediaWiki-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-l