当我试图使用HttpClient.GetStringAsync发出GET请求时,我的程序就会爆炸。
这是错误消息:
An invalid request URI was provided. The request URI must either be an absolute URI or BaseAddress must be set.
假设基于用户选择的IP,我的程序对其不同的变体提出请求,以了解哪个是可用的。例如:用户选择"192.168.0.20",那么我的程序必须向"192.168.0.1,192.168.0.2,……“发出请求。
private static readonly HttpClient client = new HttpClient();
try
{
string[] ips = cbxIps.SelectedValue.ToString().Split('.');
string ip = ips[0] + "." + ips[1] + "." + ips[2] + ".";
for (int i = 1; i < 255; i++)
{
var responseString = client.GetStringAsync(ip + i.ToString() + ":8080/alive");
if (responseString.Result == "200")
{
Servidor s = new Servidor(IPAddress.Parse(ip + i.ToString()), "Servidor " + i.ToString());
Servidor.Agregar(s);
}
}
Actualizar();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
发布于 2019-09-05 01:15:50
在调用https://)时,需要在ip地址之前指定HTTP方案(http://或GetStringAsync )
例如,
var responseString = client.GetStringAsync("https://" + ip + i.ToString() + ":8080/alive");
https://stackoverflow.com/questions/57797247
复制相似问题