【问题标题】:sending POST request to azure ML Web service using poster使用海报向 azure ML Web 服务发送 POST 请求
【发布时间】:2015-09-17 23:24:46
【问题描述】:

我已经使用 Azure ML 成功部署了一个 Web 服务,并且能够在 Azure ML 以及示例 R 客户端应用程序上获得输出。

不过,我想使用 firefox 海报获得响应。

我已按照 Azure 页面中关于部署 Web 服务的说明,并尝试使用相同的请求标头和参数,如下所示

来自天蓝色页面的说明

这是我在海报上尝试过的

错误信息

我的 R 代码有效

library("RCurl")
library("rjson")

# Accept SSL certificates issued by public Certificate Authorities
options(RCurlOptions = list(cainfo = system.file("CurlSSL", "cacert.pem", package = "RCurl")))

h = basicTextGatherer()
hdr = basicHeaderGatherer()


req = list(

        Inputs = list(


            "input1" = list(
                "ColumnNames" = list("Smoker", "GenderCD", "Age"),
                "Values" = list( list( "1", "M", "8" ),  list( "1", "M", "8" )  )
            )                ),
        GlobalParameters = setNames(fromJSON('{}'), character(0))
)

body = enc2utf8(toJSON(req))
api_key = "hHlKbffejMGohso5yiJFke0D9yCKwvcXHG8tfIL2d8ccWZz8DN8nqxh9M4h727uVWPz+jmBgm0tKBLxnPO4RyA=="
authz_hdr = paste('Bearer', api_key, sep=' ')

h$reset()
curlPerform(url = "https://ussouthcentral.services.azureml.net/workspaces/79f267a884464b6a95f5819870787918/services/e3490c06c73849f8a78ff320f7e5ffbc/execute?api-version=2.0&details=true",
            httpheader=c('Content-Type' = "application/json", 'Authorization' = authz_hdr),
            postfields=body,
            writefunction = h$update,
            headerfunction = hdr$update,
            verbose = TRUE
            )

headers = hdr$value()
httpStatus = headers["status"]
if (httpStatus >= 400)
{
    print(paste("The request failed with status code:", httpStatus, sep=" "))

    # Print the headers - they include the requert ID and the timestamp, which are useful for debugging the failure
    print(headers)
}

print("Result:")
result = h$value()
print(fromJSON(result))

我的 API 密钥

hHlKbffejMGohso5yiJFke0D9yCKwvcXHG8tfIL2d8ccWZz8DN8nqxh9M4h727uVWPz+jmBgm0tKBLxnPO4RyA==

我怎样才能形成一个有效的正确 URL?

【问题讨论】:

  • 如果这是正确答案,请标记为答案。

标签: r web-services azure azure-web-app-service azure-machine-learning-studio


【解决方案1】:

“要发送的内容”部分不正确,您指定了 URL 编码,而您需要放置 application/json。

【讨论】:

  • 很快就会回来
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-12-12
  • 2020-01-28
  • 2019-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多