<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Http request hangs at GetAsync() in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10820819#M21916</link>
    <description>&lt;P&gt;Interesting, will try it! Thank you so much for that tip!&lt;/P&gt;</description>
    <pubDate>Mon, 13 Dec 2021 22:45:55 GMT</pubDate>
    <dc:creator>ricardo.salasHND82</dc:creator>
    <dc:date>2021-12-13T22:45:55Z</dc:date>
    <item>
      <title>Http request hangs at GetAsync()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10816291#M21913</link>
      <description>&lt;P&gt;Hey everyone,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I already tried to perform the isolated request through a Console App, and it works.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;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.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The following is the related code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;[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;

        }
        
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;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&amp;lt;string&amp;gt; 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;

        }
    }&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 14:03:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10816291#M21913</guid>
      <dc:creator>ricardo.salasHND82</dc:creator>
      <dc:date>2021-12-11T14:03:13Z</dc:date>
    </item>
    <item>
      <title>Re: Http request hangs at GetAsync()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10816452#M21914</link>
      <description>&lt;P&gt;It was the TaskDialog.Show(), it was misplaced. The Execute() in ExportData was being ended before FohlioAPIConnection.ConnectionAsync() was able of finishing, therefore the TaskDialog did not have anything to show, and it got stuck there.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Rookie's async mistake.&lt;/P&gt;</description>
      <pubDate>Sat, 11 Dec 2021 16:48:40 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10816452#M21914</guid>
      <dc:creator>ricardo.salasHND82</dc:creator>
      <dc:date>2021-12-11T16:48:40Z</dc:date>
    </item>
    <item>
      <title>Re: Http request hangs at GetAsync()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10819636#M21915</link>
      <description>&lt;P&gt;Usually, I use something like this to make an async function to force to wait for the result.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="csharp"&gt;public static string Connection(HttpClient client, string endpoint)
{
    var task = Task.Run(async () =&amp;gt;
    {
        return await ConnectionAsync(client, endpoint);
    });
    return task.GetAwaiter().GetResult();
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Something like this in your case, so you don't need to call &lt;EM&gt;&lt;STRONG&gt;Result.&lt;/STRONG&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 14:54:52 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10819636#M21915</guid>
      <dc:creator>ricaun</dc:creator>
      <dc:date>2021-12-13T14:54:52Z</dc:date>
    </item>
    <item>
      <title>Re: Http request hangs at GetAsync()</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10820819#M21916</link>
      <description>&lt;P&gt;Interesting, will try it! Thank you so much for that tip!&lt;/P&gt;</description>
      <pubDate>Mon, 13 Dec 2021 22:45:55 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/http-request-hangs-at-getasync/m-p/10820819#M21916</guid>
      <dc:creator>ricardo.salasHND82</dc:creator>
      <dc:date>2021-12-13T22:45:55Z</dc:date>
    </item>
  </channel>
</rss>

