Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void GetDataFromRestService()
- {
- string userName = "gopal@cctspl.com";
- string password = "gopal@cctspl.com";
- var request = HttpWebRequest.Create("http://cloudapps.cctspl.com/_vti_bin/authentication.asmx");
- //SetBasicAuthHeader(request, "gopal@cctspl.com", "gopal@cctspl.com");
- string authInfo = userName + ":" + password;
- authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));
- request.Headers["Authorization"] = "Basic " + authInfo;
- request.ContentType = "application/json";
- request.Method = "GET";
- using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
- {
- Log.Debug("Status Code :", "" + response.StatusCode);
- RunOnUiThread(() =>
- { txtStatus.Text = response.StatusCode.ToString();
- });
- if (response.StatusCode != HttpStatusCode.OK)
- {
- Console.Out.WriteLine("ERROR: Server status code: {0}", response.StatusCode);
- }
- using (StreamReader reader = new StreamReader(response.GetResponseStream()))
- {
- var content = reader.ReadToEnd();
- if (string.IsNullOrWhiteSpace(content))
- {
- Console.Out.WriteLine("ERROR: Empty response.");
- }
- else
- {
- Console.Out.WriteLine("Response: {0}", content);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement