1

I am trying to connect to a web service from Lockheed Martin located here. I have looked at other examples and am using the following code to try and establish a connection. All I want to know at this point is if I have established a connection and been authorized but I repeatedly get an exception saying

Unauthorized at System.Net.HttpWebRequest.GetResponse()

. Am I setting up the web request and response correctly? Is there a different method that would simply let me know if I've successfully connected?

            try
        {
            //Connect to the Lockheed Martin web client

            WebRequest client = WebRequest.Create("https://www.elabs.testafss.net/Website2/ws");
            string username = "username";
            string password = "password";
            string credentials = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(username + ":" + password));
            client.Headers.Add("Authorization", "Basic " + credentials);
            WebResponse response = client.GetResponse();
            Console.WriteLine(((HttpWebResponse)response).StatusDescription);
        }
        catch (Exception ex)
        {
            Console.WriteLine(ex);
        }
Mike S
  • 11
  • 1

1 Answers1

0

Probably your user / password is incorrect, looking at the documentation of the web service, your code is reproducing the exactly same hash that is in following sample:

Authentication - Basic Auth

Authentication is performed using the Basic Auth protocol. An authorization header is supplied with every web service request. This is sometimes called pre-emptive authentication. The header looks like this:
Authorization: Basic Vendor_ID:Vendor_Password
where the Vendor_ID:Vendor_Password string is converted to Base64.

Example

Authorization: Basic JoesFlightServices:SecretPW
Converted to Base64:
Authorization: Basic Sm9lc0ZsaWdodFNlcnZpY2VzOlNlY3JldFBX
Note that conversion to Base64 does not ensure the information will be private. We use HTTPS to encrypt the entire HTTP message including the headers.

Source

Community
  • 1
  • 1
Rafael Delboni
  • 817
  • 8
  • 13