空间站跟踪网页响应控制
通过返回一个 HTTPResponse 可以从一个云对象控制 HTTP 响应的确切特征. 错误情形可用 HTTPErrorResponse 处理.
定义函数,找到离国际空间站当前位置最近的城市. 空间站移动迅速,因而结果也快速变化.
显示完整的 Wolfram 语言输入
In[2]:=

issLocationDisplay[]
Out[2]=

部署每次都作计算的云对象,用 HTTPResponse 指出内容类型,并指定一个头,告诉浏览器不要缓存结果.
In[3]:=

obj = CloudDeploy[
Delayed[HTTPResponse[
ExportString[issLocationDisplay[], "PNG"], <|
"ContentType" -> "image/png",
"Headers" -> {"Cache-Control" -> "no-cache"}|>]],
CloudObject["iss-location"], Permissions -> "Public"]
禁止某些用户使用云对象,返回 HTTPErrorResponse.
In[4]:=

obj = CloudDeploy[Delayed[
If[MemberQ[{"badapple@example.com", "blackhat@example.com",
"spammer@example.com"}, $WolframID],
HTTPErrorResponse[403],
HTTPResponse[
issLocationDisplay[], <|
"Headers" -> {"Cache-Control" -> "no-cache"}|>]
]], CloudObject["iss-location"], Permissions -> "Public"]