I want to consume a service at http://www.esvapi.org/api/#sample. The sample code in the link is
C# REST StringBuilder sUrl = new StringBuilder(); sUrl.Append("http://www.esvapi.org/v2/rest/passageQuery"); sUrl.Append("?key=IP"); sUrl.Append("&passage=" + Server.UrlEncode("Matthew 5").ToString()); sUrl.Append("&include-headings=true"); WebRequest oReq = WebRequest.Create(sUrl.ToString()); StreamReader sStream = new StreamReader(oReq.GetResponse().GetResponseStream()); StringBuilder sOut = new StringBuilder(); sOut.Append(sStream.ReadToEnd()); sStream.Close(); Response.Write(sOut.ToString());
I rewrote it with my own.
var strSearch = "John 3:16"; var options = "include-passage-references=true"; var client = new WebClient(); var query = string.Format("www.esvapi.org/v2/rest/passageQuery?key={0}&passage={1}&options={2}", "IP", Server.UrlEncode(strSearch), options); var result = client.DownloadString(query);
However I got an exception which is "System.ArgumentException: Illegal characters in path."
The variable query is
www.esvapi.org/v2/rest/passageQuery?key=IP&passage=John+3%3a16&options=include-passage-references=true
What is wrong?