0

So I have this code:

    partial void runflooder (Foundation.NSObject sender) {
            string[] links;
            {
                links = new string[amount];
                for (int i = 0; i < links.Length; i++)
                {
                    email = $"ghoulrotmg{RandomString(10)}@gmail.com";
                    links[i] = "http://" + serverIP
                        + ":" + serverPort + "/account/register?isAgeVerified=1&entrytag=&ignore=77240&newPassword=ghoulrotmg&newGUID="
                        + email + "&guid=597BFBCFA0E1C4195FD6E8392557CD960361878D%22";
                generateaccountsprogress.MaxValue = amount;                              
                generateaccountsprogress.IncrementBy(amount);
            }            
        runflooderlabel.StringValue = string.Format("App is running.");
        runflooderlabel.TextColor = NSColor.SystemGreenColor;
            for (int i = 0; i < links.Length; i++) {
                WebRequest request = WebRequest.Create(links[i]);
            }
            progress.MaxValue = amount;                              
            progress.IncrementBy(amount);            
    }

}

What I want to do, is generate links. Then, I want the app to visit those links that have been created. However, it isn't making any requests to the website. The links generated are fine, and are tested to be working (I wrote them to a file and it works). The error is obviously in here:

        for (int i = 0; i < links.Length; i++) {
            WebRequest request = WebRequest.Create(links[i]);
        }

Can someone help me solve this issue.

2
  • Did you debug it? If you did and the for loop runs what is the exception message? Commented Jul 15, 2018 at 12:41
  • Yes, I have debugged it, there were no error messages. Commented Jul 16, 2018 at 3:57

2 Answers 2

4

You're just creating the WebRequest; you have to call .GetResponse() to actually make the request.

As a side note, unless you need to target NET 3.5 or lower, using HttpClient is the more modern, and arguably quite easier, way to do this.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello, I'll try out the HttpClient and the .GetResponse(). Thanks again.
0

Thanks guys, I solved the issue.

I was missing a GetResponse() for my code.

Here is how I did it:

for (int i = 0; i < links.Length; i++) 
{
    var request    = WebRequest.Create(links[i]);
    var response   = (HttpWebResponse)request.GetResponse();
    var dataStream = response.GetResponseStream();                    
    var reader     = new StreamReader(dataStream);
    var responseFromServer = reader.ReadToEnd();

    Console.WriteLine (responseFromServer);
    reader.Close();
    dataStream.Close();
    response.Close(); 
}

Most of it is directly from the Microsoft docs.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.