I've been trying to use a RESTful XML service that brings back extra data on a search using names or last names. The way I am suppose to authenticate is by using a separate REST API request that gives me access to the rest of the services. But by the time I call the second request it sends me the following error. "The remote server returned an error: (401) Unauthorized.". The user and password that I'm using are the correct ones so I'm a bit stuck on why this message is being sent.
using System.Net; using System.IO; using System.Xml; using System.Xml.XPath; private void btnSearch_Click(object sender, EventArgs e) { string sURL, aURL; sURL = "http://url.com/data/qws/access?var1=user&var2=password"; aURL = "http://url.mx/data/qws/pepsp?name=miguel&lastname=osorio"; CookieContainer cookieQ = new CookieContainer(); HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(sURL); request.CookieContainer = cookieQ; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); request = (HttpWebRequest)HttpWebRequest.Create(aURL); request.CookieContainer = cookieQ; response = (HttpWebResponse)request.GetResponse(); using (response) { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(response.GetResponseStream()); XmlNode name = xmlDoc.SelectSingleNode("/xml/person/name"); XmlNode lastname = xmlDoc.SelectSingleNode("/xml/person/lastname"); MessageBox.Show(name.InnerText + ' ' + lastname.InnerText); } }
No comments:
Post a Comment