The Forge Platform documentation is not easy to understand for a pure C # or VB.Net programmer.
Autodesk documented the call using cURL. I would like to explain in my new posting on Forge how cURL can be translated into C #.
CURL describes the request (REQUEST) to the web service, here Forge. .Net framework has no function that translates cURL directly.
One way to build a request would be to use RestSharp. RestSharp can be added to the application as a NuGet package.
The following table lists the options (those with the leading minus sign).
Options | Description | RestSharp |
-v | Method or URI | |
-x | HTTP method type | Method.Get or Method.Post |
-H | Header | Several header parameter are possible |
-d | Parameter data | i.e.Client-ID |
The following code snippet shows how to build a RestSharp.RestRequest. This requires a RestSharp.
The URL (variable: m_URL) corresponds to the -v option in the cURL. The method of the option -x.
string m_Url = "https://developer.api.autodesk.com/authentication/v1/gettoken"; RestRequest m_Request = new RestRequest(m_Url, Method.POST);}
m_Request.AddHeader("Content-Type", "application/x-www-form-urlencoded"); //Alternative Dictionary<string, string> m_Headers = new Dictionary<string, string>(); m_Headers.Add("Content-Type", "application/x-www-form-urlencoded"); foreach (KeyValuePair<string, string> m_Header in m_Headers) { m_Request.AddHeader(m_Header.Key, m_Header.Value); }
Once the request has been compiled, the client can be instantiated. This client starts the request and returns the result (response). There are some Execute methods available that need to be selected according to the situation. An asynchronous execution is preferable so that the application does not stop.
Only if the StatusCode = OK is an evaluatable result available in the Content response property. In the case of Forge, the format is a JSon format and should be evaluated accordingly.
RestClient m_RestClient = new RestClient("https://developer.api.autodesk.com"); IRestResponse m_Response = await m_RestClient.ExecuteTaskAsync(m_Request); switch(m_Response.StatusCode) { case System.Net.HttpStatusCode.OK: string m_Result = m_Response.Content; break; }
© Copyright 2019 by CAD-Becker.de
When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.
|
Dipl.-Ing. Jürgen A. Becker Versorgungstechnik |
![]() |
Jürgen A. Becker
CAD-Becker.de
Detmolder Str. 786
33699 Bielefeld
Germany
Telephone
+49 (5202) 9953808
Mobile
+49 170 870 8679
E-Mail
Juergen.Becker(at)CAD-Becker.de