none
HTTP url RRS feed

  • Question

  • Could i access to my usrname and pass to url in this code? if yes how

     public static string HttpGet(string URI)
            {
                System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
                //req.Proxy = new System.Net.WebProxy(ProxyString, true); //true means no proxy
                System.Net.WebResponse resp = req.GetResponse();
                System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                string result= sr.ReadToEnd().Trim();
                MessageBox.Show(result);
                return result;
            }

    Friday, May 31, 2019 7:24 AM

Answers

  • Hi

    I have modified the code according to the link.

    Code:

    public static string HttpGet(string URI)
            {
                System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
                req.Credentials = new NetworkCredential("username", "password");
                System.Net.WebResponse resp = req.GetResponse();
                System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                string result= sr.ReadToEnd().Trim();
                MessageBox.Show(result);
                return result;
            }

    If you still have trouble in this question, please feel free to let us know.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by CoolDadTxModerator Friday, May 31, 2019 1:43 PM
    • Marked as answer by Ahron321 Saturday, June 1, 2019 5:23 AM
    Friday, May 31, 2019 9:06 AM
    Moderator

All replies

  • Hi Ahron321,

    Thank you for posting here.

    For your question, I am not sure what you mean, could you give a example?

    We are waiting for your update.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 31, 2019 7:39 AM
    Moderator
  • something like that with login info on the url

    WebClient client = new WebClient();
                String username = u;
                String password = p;
                string url = "url";
    
                client.Credentials = new System.Net.NetworkCredential(username, password);
    
                string credentials = Convert.ToBase64String(Encoding.ASCII.GetBytes(username + ":" + password));
    
                client.Headers[HttpRequestHeader.Authorization] = "Basic " + credentials;
    
                var result = client.DownloadString(url);
                users = result;

    Friday, May 31, 2019 7:43 AM
  • Hi

    Thanks for the feedback.

    I want to know if you want to get username from URL and pass it to URL.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 31, 2019 8:15 AM
    Moderator
  • i have a url that have login on the start and i need it will login with that code:

    like username and password

     public static string HttpGet(string URI)
            {
                System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
                //req.Proxy = new System.Net.WebProxy(ProxyString, true); //true means no proxy
                System.Net.WebResponse resp = req.GetResponse();
                System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                string result= sr.ReadToEnd().Trim();
                MessageBox.Show(result);
                return result;
            }


    • Edited by Ahron321 Friday, May 31, 2019 8:23 AM
    Friday, May 31, 2019 8:18 AM
  • Hi

    Based on my search, the following link could be helpful for you.

    https://stackoverflow.com/questions/26665911/c-sharp-login-to-website-using-httpwebrequest

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, May 31, 2019 8:46 AM
    Moderator
  • no, it wont help me
    Friday, May 31, 2019 8:55 AM
  • Hi

    I have modified the code according to the link.

    Code:

    public static string HttpGet(string URI)
            {
                System.Net.WebRequest req = System.Net.WebRequest.Create(URI);
                req.Credentials = new NetworkCredential("username", "password");
                System.Net.WebResponse resp = req.GetResponse();
                System.IO.StreamReader sr = new System.IO.StreamReader(resp.GetResponseStream());
                string result= sr.ReadToEnd().Trim();
                MessageBox.Show(result);
                return result;
            }

    If you still have trouble in this question, please feel free to let us know.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by CoolDadTxModerator Friday, May 31, 2019 1:43 PM
    • Marked as answer by Ahron321 Saturday, June 1, 2019 5:23 AM
    Friday, May 31, 2019 9:06 AM
    Moderator
  • thanks but one more thing, why does the url shows in http debugger ?
    Friday, May 31, 2019 4:59 PM
  • Why would it not show up?

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Friday, May 31, 2019 5:38 PM
  • cuz this code should hide it no?
    Friday, May 31, 2019 5:44 PM