是 APIFunction 和相关函数的一个选项,指定是否应该接受影响总的云执行的参数.
AllowedCloudExtraParameters
是 APIFunction 和相关函数的一个选项,指定是否应该接受影响总的云执行的参数.
更多信息
- AllowedCloudExtraParameters 的设置可以是 All、None 或一个列表.
- AllowedCloudExtraParameters 设置中的典型参数包括:
-
"_timeout" 等价于 TimeConstrained "_memorylimit" 等价于 MemoryConstrained "_geolocation" 等价于设置 $GeoLocation "_exportform" 等价于 ExportForm "_responseform" 等价于 ResponseForm - 额外参数的值使用 Interpreter 规范进行诠释:
-
"_timeout" Restricted["Quantity","Seconds"] "_memorylimit" Restricted["Quantity","Bytes"] "_geolocation" "Location" "_exportform" "ExportFormatString" "_responseform" Restricted["ExportFormatString",…] - "_responseform" 的限制是{{"XML","JSON","RawJSON","WL","String","Text","HTML","HTMLFragment"}}.
范例
打开所有单元 关闭所有单元基本范例 (1)
允许 APIFunction 的调用者设置导出结果的格式:
api = CloudDeploy @ APIFunction[
"x" -> "String",
Identity,
AllowedCloudExtraParameters -> {"_exportform", "_responseform"}
]URLRead[
URLBuild[api, {"x" -> "something", "_exportform" -> "JSON"}],
"Body"
]如果 "_exportform" 参数没有在调用中指定,APIFunction 不会导出结果:
URLRead[
URLBuild[api, {"x" -> "something"}],
"Body"
]范围 (5)
当 AllowedCloudExtraParameters 设为 "_exportform",响应可用 $ExportFormats 中的任何格式导出,并覆盖指定的导出格式:
api = CloudDeploy @ APIFunction[
"x" -> "String",
Identity,
"JSON",
AllowedCloudExtraParameters -> {"_exportform"}
]URLRead[
URLBuild[api, {"x" -> "something", "_exportform" -> "XML"}],
"Body"
]当 AllowedCloudExtraParameters 设为 "_responseform",会返回结果的 ResponseForm:
api = CloudDeploy @ APIFunction[
"x" -> "Integer",
1 / #x &,
AllowedCloudExtraParameters -> {"_responseform"}
]URLRead[
URLBuild[api, {"x" -> "0", "_responseform" -> "JSON"}],
"Body"
]当 AllowedCloudExtraParameters 设为 "_geolocation",客户可以指定不同的 $GeoLocation:
api = CloudDeploy @ APIFunction[
"city" -> "City",
GeoGraphics[Arrow@GeoPath[{$GeoLocation, #city}], GeoBackground -> "ReliefMap"] &,
"PNG",
AllowedCloudExtraParameters -> {"_geolocation"}
]URLExecute[api, {"city" -> "rome", "_geolocation" -> "lisbon"}, "PNG"]当 AllowedCloudExtraParameters i设为 "_memorylimit",客户可以指定内存使用的限制:
api = CloudDeploy@APIFunction[
"size" -> "Integer",
RandomImage[1, {#size, #size}]&,
"PNG",
AllowedCloudExtraParameters -> "_memorylimit"
]URLExecute[api, {"_memorylimit" -> "30000", "size" -> "100000"}]当 AllowedCloudExtraParameters 设为 "_timeout",客户可以指定执行的时间限制:
api = CloudDeploy@APIFunction[
"sec" -> "Integer",
Pause[#sec]&,
AllowedCloudExtraParameters -> "_timeout"
]URLExecute[api, {"_timeout" -> "0.1", "sec" -> "1"}]属性和关系 (2)
允许 "_exportform",有效地等价于设置 APIFunction 的第三个参数:
api1 = CloudDeploy[
APIFunction["x" -> "Integer", Identity, AllowedCloudExtraParameters -> "_exportform"]
]api2 = CloudDeploy[
APIFunction["x" -> "Integer", Identity, "JSON"]
]URLRead[
URLBuild[api1, {"x" -> "1", "_exportform" -> "JSON"}],
"Body"
] === URLRead[
URLBuild[api2, {"x" -> "1"}],
"Body"
]允许 "_responseform",有效地等价于在 ResponseForm 中包装 APIFunction 主体:
api1 = CloudDeploy[
APIFunction["x" -> "Integer", 1 / #x&, AllowedCloudExtraParameters -> "_responseform"]
]api2 = CloudDeploy[
APIFunction["x" -> "Integer", ResponseForm[1 / #x, "JSON"]&]
]ImportString[
URLRead[
URLBuild[api1, {"x" -> "0", "_responseform" -> "JSON"}], "Body"], "RawJSON"]["Result"]& /@ {api1, api2}可能存在的问题 (1)
让 API 调用者设置 "_responseform" 可能暴露部署 API 的细节,例如内部消息:
myFun::message = "Something embarassing happened.";
myFun[2] := (Message[myFun::message];2)
myFun[x_] := x
api = CloudDeploy[APIFunction["x" -> "Integer", myFun[#x]&, AllowedCloudExtraParameters -> {"_responseform"}]]URLRead[
URLBuild[api, {"x" -> "2", "_responseform" -> "JSON"}],
"Body"
]相关指南
-
▪
- 云执行元数据
相关的工作流程
- 部署网络 API
文本
Wolfram Research (2017),AllowedCloudExtraParameters,Wolfram 语言函数,https://reference.wolfram.com/language/ref/AllowedCloudExtraParameters.html.
CMS
Wolfram 语言. 2017. "AllowedCloudExtraParameters." Wolfram 语言与系统参考资料中心. Wolfram Research. https://reference.wolfram.com/language/ref/AllowedCloudExtraParameters.html.
APA
Wolfram 语言. (2017). AllowedCloudExtraParameters. Wolfram 语言与系统参考资料中心. 追溯自 https://reference.wolfram.com/language/ref/AllowedCloudExtraParameters.html 年
BibTeX
@misc{reference.wolfram_2026_allowedcloudextraparameters, author="Wolfram Research", title="{AllowedCloudExtraParameters}", year="2017", howpublished="\url{https://reference.wolfram.com/language/ref/AllowedCloudExtraParameters.html}", note=[Accessed: 18-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_allowedcloudextraparameters, organization={Wolfram Research}, title={AllowedCloudExtraParameters}, year={2017}, url={https://reference.wolfram.com/language/ref/AllowedCloudExtraParameters.html}, note=[Accessed: 18-August-2026]}