0

I have an Azure Durable Function that sends some HTTP request via VNet. Ones in a while the following method throws a 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);
    }

The requested address is not valid in its context

Is it a problem of VNet or how should I approach this problem?

Chris Gillum
  • 14,526
  • 5
  • 48
  • 61
Andrej Z.
  • 45
  • 6

1 Answers1

0

This error is thrown at the TCP layer. A quick search shows that it most often happens when trying to bind to a IP address which isn't valid, like 0.0.0.0. I would start by looking at the URI value you're using to determine whether it corresponds to something you expect.

Chris Gillum
  • 14,526
  • 5
  • 48
  • 61