Message 1 of 4
Http request hangs at GetAsync()
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hey everyone,
I am trying to develop for the first time an integration with a third-party API, but when I try to execute a GET request Revit just locks and I have to terminate it through the Task Manager. I am not exactly sure why this is happening.
I already tried to perform the isolated request through a Console App, and it works.
When I try to debug it, everything seems to be working and all the values being assigned correctly, but it just hangs at the GetAsync() in the FohlioAPIConnection class.
The following is the related code:
[Transaction(TransactionMode.Manual)]
internal class ExportData : IExternalCommand
{
public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
{
HttpClient client = FohlioAPIConnection.InitializeClient();
var getResponse = FohlioAPIConnection.ConnectionAsync(client, "projects");
TaskDialog.Show("Result", getResponse.Result);
return Result.Succeeded;
}
}
internal class FohlioAPIConnection
{
public static HttpClient InitializeClient()
{
HttpClient client = new HttpClient();
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(Environment.GetEnvironmentVariable("FOHLIO_TOKEN"));
return client;
}
public static async Task<string> ConnectionAsync(HttpClient client, string endpoint)
{
HttpResponseMessage responseMessage = await client.GetAsync(new Uri("https://www.fohlio.com/openapi/projects"));
var result = await responseMessage.Content.ReadAsStringAsync();
return result;
}
}