Advertisement
Guest User

Untitled

a guest
Aug 9th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. public void GetDataFromRestService()
  2. {
  3. string userName = "gopal@cctspl.com";
  4. string password = "gopal@cctspl.com";
  5. var request = HttpWebRequest.Create("http://cloudapps.cctspl.com/_vti_bin/authentication.asmx");
  6. //SetBasicAuthHeader(request, "gopal@cctspl.com", "gopal@cctspl.com");
  7. string authInfo = userName + ":" + password;
  8. authInfo = Convert.ToBase64String(Encoding.UTF8.GetBytes(authInfo));
  9. request.Headers["Authorization"] = "Basic " + authInfo;
  10. request.ContentType = "application/json";
  11. request.Method = "GET";
  12. using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
  13. {
  14. Log.Debug("Status Code :", "" + response.StatusCode);
  15. RunOnUiThread(() =>
  16. { txtStatus.Text = response.StatusCode.ToString();
  17. });
  18. if (response.StatusCode != HttpStatusCode.OK)
  19. {
  20. Console.Out.WriteLine("ERROR: Server status code: {0}", response.StatusCode);
  21. }
  22. using (StreamReader reader = new StreamReader(response.GetResponseStream()))
  23. {
  24. var content = reader.ReadToEnd();
  25. if (string.IsNullOrWhiteSpace(content))
  26. {
  27. Console.Out.WriteLine("ERROR: Empty response.");
  28. }
  29. else
  30. {
  31. Console.Out.WriteLine("Response: {0}", content);
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement