【问题标题】:Headers in !ACESAPI:acesHttpOperation - Autodesk Forge!ACESAPI:acesHttpOperation 中的标题 - Autodesk Forge
【发布时间】:2021-10-16 07:20:20
【问题描述】:

我在我的工作项中使用 OnProgress 回调,但是当我尝试使用 !ACESAPI:acesHttpOperation 发送标头时遇到以下困难。

[08/12/2021 22:59:57] !ACESAPI:acesHttpOperation(GetFormaletas,?pk=30204db6-fe6c-4368-99a0-972781eb66c9,Authorization:Api-Key UI3rAhEG.rP5qlYHuwmw9664udwB9cbKs2OXMpMhX,,file://30204db6-fe6c-4368-99a0-972781eb66c9formaletas.csv)

您可以在下面看到每个参数接收到的内容。

[08/12/2021 22:59:57] !!!!This is an API callback => "!ACESAPI:acesHttpOperation(GetFormaletas,?pk=30204db6-fe6c-4368-99a0-972781eb66c9,Authorization:Api-Key UI3rAhEG.rP5qlYHuwmw9664udwB9cbKs2OXMpMhX,,file://30204db6-fe6c-4368-99a0-972781eb66c9formaletas.csv)"
[08/12/2021 22:59:57] Start processing API request acesHttpOperation.
[08/12/2021 22:59:57] Arguments => name="GetFormaletas", suffix="?pk=30204db6-fe6c-4368-99a0-972781eb66c9", headers="Authorization:Api-Key UI3rAhEG.rP5qlYHuwmw9664udwB9cbKs2OXMpMhX", requestContent="", responseFile="file://30204db6-fe6c-4368-99a0-972781eb66c9formaletas.csv"
[08/12/2021 22:59:57] - Download variadic item from "http://e320ece2e3e5.ngrok.io/projects/get-formaletas-csv?pk=30204db6-fe6c-4368-99a0-972781eb66c9" to "T:\Aces\Jobs\8b53409106af4388855f42e3c4e80f1c\30204db6-fe6c-4368-99a0-972781eb66c9formaletas.csv".

但由于缺少授权标头,我得到了 403。

[08/12/2021 22:59:57] Error: API failed. Reason = Processing of the HTTP request resulted in an exception. Please see the HTTP response returned by the 'Response' property of this exception for details.
[08/12/2021 22:59:57] Error: Response = StatusCode: 403, ReasonPhrase: 'Forbidden', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:

在服务器中,当我打印请求标头时,也可以看到缺少标头

Received headers ==> {'Host': 'e320ece2e3e5.ngrok.io', 'X-Forwarded-For': '3.212.238.83', 'X-Forwarded-Proto': 'http', 'Accept-Encoding': 'gzip'}
Forbidden: /projects/get-formaletas-csv
HTTP GET /projects/get-formaletas-csv?pk=30204db6-fe6c-4368-99a0-972781eb66c9 403 [0.00, 127.0.0.1:54139]

在文档中我没有看到带有标题的示例,欢迎提供任何指导。我也想知道如何发送多个标头。

提前非常感谢!

【问题讨论】:

    标签: autodesk-forge


    【解决方案1】:

    如果您使用的是 Design Automation API for Inventor,则其 VS 模板 项目实际上包含一个帮助函数,因此您可以这样调用它: p>

    var dict = new Dictionary<string, string>();
    dict.Add("MyHeader-Item1", "MyHeader Value1");
    dict.Add("MyHeader-Item2", "MyHeader Value2");
    Autodesk.Forge.DesignAutomation.Inventor.Utils.OnDemand.HttpOperation("OnDemandParam", "", dict, "file://myfile");
    

    我在工作项报告中检查了生成的内容,它在这里:

    !ACESAPI:acesHttpOperation(OnDemandParam,,MyHeader-Item1=MyHeader Value1;MyHeader-Item2=MyHeader Value2,,file://myfile)
    

    另外,检查webhook.site 以确保它工作正常 - 它确实:

    还更新了 https://forge.autodesk.com/blog/communicate-servers-inside-design-automation 以将其作为示例包含在内。

    【讨论】:

    • 我正在使用 Design Automation API for revit,但根据您的建议,我已经可以使用它了,非常感谢。
    猜你喜欢
    • 2021-10-02
    • 2021-10-16
    • 2020-06-03
    • 2021-07-03
    • 2021-09-25
    • 2018-05-21
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    相关资源
    最近更新 更多