basic authentication passes in postman, it passes when i login through harvests webpage but dont passes in my c# code. What is wrong in my code. When i use another account with the same uri. It passes. the error comes in this line (response = request.GetResponse() as HttpWebResponse)

    HttpWebRequest request;
    HttpWebResponse response = null;
    uri = "https://laios.harvestapp.com/projects";

        request = WebRequest.Create(uri) as HttpWebRequest;
        request.MaximumAutomaticRedirections = 1;
        request.AllowAutoRedirect = true;

        request.Accept = "application/json";
        request.ContentType = "application/json";
        request.UserAgent = "harvest_api_sample.cs";

        request.Headers.Add("Authorization", "Basic " + Convert.ToBase64String(new ASCIIEncoding().GetBytes(usernamePassword)));

        using (response = request.GetResponse() as HttpWebResponse)
        {
            reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
            using (StreamWriter writer = new StreamWriter(jsonPath))
            {
                sbSource = new StringBuilder(reader.ReadToEnd());
                writer.WriteLine(sbSource);
                writer.Close();
                reader.Close();

            }
        }

        reader = new StreamReader(jsonPath);
        string jsonString = reader.ReadToEnd();
0

There are 0 answers