简体   繁体   中英

C# Why i can't send a request with my url?

Hi i need to know why my url don't take request but when i ping him it's work.

static async void check(string ip)
{
   string url = "http://" + ip + "/";
   try
   {
      HttpResponseMessage response = await client.GetAsync(url);
      response.EnsureSuccessStatusCode();
      string responseBody = await response.Content.ReadAsStringAsync();
      Console.WriteLine("\n{0} ==> OK\n", url);
      Console.WriteLine(responseBody);
   }
   catch (HttpRequestException e)
   {
      Console.WriteLine("\n{0} ==> Exception Caught!", url);
      Console.WriteLine("Message :{0} ", e.Message);
   }
}

Output:
Exception thrown: 'System.Net.Http.HttpRequestException' in mscorlib.dll http://192.168.0.236/ ==> Exception Caught!
Message:There was an error when the request was sent.

On the HTML website:

General:
Request URL: http://192.168.0.236/setup.html

Request Method: GET

Status Code: 200 OK

Remote Address: 192.168.0.236:80

Referrer Policy: strict-origin-when-cross-origin

Response Header:
HTTP/1.1 200 OK

Content-Type: text/html; charset=Windows-1252

Server: Volumic

Cache-Control: no-store, no-cache, must-revalidate

Pragma: no-cache

Connection: close

Request Header:
GET /setup.html HTTP/1.1

Host: 192.168.0.236

Connection: keep-alive

Cache-Control: max-age=0

Upgrade-Insecure-Requests: 1

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.67 Safari/537.36 Edg/87.0.664.52

Accept:text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng, / ;q=0.8,application/signed-exchange;v=b3;q=0.9

Referer: http://192.168.0.236/

Accept-Encoding: gzip, deflate

Accept-Language: fr,fr-FR;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6

Cookie: sessionToken=48699711

Can someone help me understand where the problem of my url comes from?

Check if external traffic (internet) can access your server's port 80? When you browse the IP address it should return the iis welcome page or the application that you installed (on port 80)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM