Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9106227
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:17:21+00:00 2026-06-17T02:17:21+00:00

This is my first attempt at creating a console app which can make a

  • 0

This is my first attempt at creating a console app which can make a HTTP GET request and print the response to the console.

Thus far, the code works, but only for URIs which do not require a username/password.

My ultimate purpose is to use a cloud/hosting API which accepts HTTP GET requests as triggers for taking certain actions. As such, I have to use a username/password for this.

using System;
using System.Net;
using System.IO;

namespace HttpTestProject {

    class Program {

        static void Main(string[] args) {

            Uri uri = new Uri("http://www.google.com");
            string username = "asdf";
            string password = "asdf";

            NetworkCredential cred = new NetworkCredential(username, password);
            CredentialCache cache = new CredentialCache();
            cache.Add(uri, "Basic", cred);

            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
            HttpWebResponse response = (HttpWebResponse)request.GetResponse();
            Stream resStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(resStream);
            string text = reader.ReadToEnd();

            Console.WriteLine(text);
            Console.ReadLine();

        }

    }

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T02:17:22+00:00Added an answer on June 17, 2026 at 2:17 am

    If you have to add basic authentication to your request without waiting for a challenge you can append the header manually:

    var request = WebRequest.Create("http://myserver.com/service");
    string authInfo = userName + ":" + userPassword;
    authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));
    
    //like this:
    request.Headers["Authorization"] = "Basic " + authInfo;
    
    var response = request.GetResponse();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Up front: This is my first attempt at an Android app. I'm in that
I'm using Visual Web Developer 2010 Express. This is my first attempt at creating
This is my first attempt at creating a Windows service that calls multiple threads.
This is my first attempt at creating a package, so I must be missing
This is my first ever attempt at creating an svn repository and I'm confused.
First attempt at a RoR project and following http://guides.rubyonrails.org/getting_started.html#creating-the-blog-application . I've got the Welcome
This is my first attempt at creating a custom instance of a class such
This is my first attempt at creating my own thread pool. The program works
This is my first attempt at creating a service and incorporating it in my
This is my first attempt at responsive design, so I'm keeping it simple. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.