none
fake url request RRS feed

  • Question

  • how do i fix this code with a display messagebox on the end

    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.StreamReadersr = new System.IO.StreamReader(resp.GetResponseStream());
    return sr.ReadToEnd().Trim();
    }

    Thursday, May 30, 2019 9:55 PM

Answers

  • Hi Ahron321,

    If you want to display the string on the end, you could try the following code.

     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;
            }

    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.

    • Marked as answer by Ahron321 Friday, May 31, 2019 7:00 AM
    Friday, May 31, 2019 6:38 AM
    Moderator

All replies

  • I guess you could try something like this

    public static string HttpGet(string URI)
    {
    try{
    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.StreamReadersr = new System.IO.StreamReader(resp.GetResponseStream());
    return sr.ReadToEnd().Trim();
    }
    catch
    {
    Messagebox.Show("An error has occurred");
    return "";
    }
    }

    Friday, May 31, 2019 12:32 AM
  • Hi Ahron321,

    Welcome to the MSDN forum.

    It seems this issue is about the C# development and our forum is to discuss the VS IDE, I will help you move this thread to the appropriate forum for professional support, thanks for your cooperation.

    Best regards,

    Sara


    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 6:04 AM
  • can i display the text inside the url?
    Friday, May 31, 2019 6:22 AM
  • Hi Ahron321,

    If you want to display the string on the end, you could try the following code.

     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;
            }

    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.

    • Marked as answer by Ahron321 Friday, May 31, 2019 7:00 AM
    Friday, May 31, 2019 6:38 AM
    Moderator
  • Thanks for the help everyone
    Friday, May 31, 2019 7:01 AM
  • There are a away to use username and password like this:

    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;
                return false;

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

    Thanks for the feedback.

    If you have a new question, you could create a new thread in c# forum.

    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:15 AM
    Moderator