我有一个通过 VNet 发送一些 HTTP 请求的 Azure 持久函数。稍后,以下方法会引发 SocketException:
public async Task<(HttpStatusCode statusCode, string Content)> PostAsync(string uri ,string json)
{
if (string.IsNullOrEmpty(uri))
{
throw new ArgumentException("message", nameof(uri));
}
var client = new HttpClient
{
BaseAddress = new Uri(uri)
};
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("", content);
string responseContent = await response.Content.ReadAsStringAsync();
return (response.StatusCode, responseContent);
}
请求的地址在其上下文中无效
是 VNet 的问题还是我应该如何解决这个问题?