Hi Joseph,
Thank you for the kind words about Excel-DNA.
Can you try a slightly simpler version of your function:
public static string Post(string uri, string json)
{
StringContent content = new StringContent(json, Encoding.UTF8, "application/json");
HttpResponseMessage response = Client.PostAsync(uri, content).Result;
if (!response.IsSuccessStatusCode)
{
throw new HttpRequestException($"Response {response.StatusCode} from {uri}");
}
return response.Content.ReadAsStringAsync().Result;
}
This eliminates the extra Task and Wait() calls, which should not make a difference, but there might be some surprise.
Then I would suggest checking some ‘Get’ calls against a public site or service, so that you can make something I can try out too.
For the simplest case it seems to work fine for me:
public static class Functions
{
static HttpClient _client = new HttpClient();
public static string CallHttp(string url)
{
var response = _client.GetAsync(url).Result;
return response.Content.ReadAsStringAsync().Result;
}
}
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/4f97a470-92ee-4da7-9ea9-60ee6ead96fan%40googlegroups.com.
This is a simple PSOT against a public server:
public static string CallHttpPost(string info)
{
var url = https://httpbin.org/post;
var content = new StringContent(info);
var response = _client.PostAsync(url, content).Result;
return response.Content.ReadAsStringAsync().Result;
}
It seems to work OK for me.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/e77f5caf-6795-4dea-8993-2ef5a47772dfn%40googlegroups.com.