working azure machine learning - text analytics rest api, located here. requires sending payload server via post. trying similar results ibm watson
here tried in console app, here's core code:
static irestresponse getresp(string url, string key, string jsontext) { irestclient client = new restclient(url); irestrequest request = new restrequest() { requestformat = dataformat.json }; request.addheader("content-type", "application/json"); request.addheader("ocp-apim-subscription-key", key); irestresponse response = client.executeaspost(request, "post");
}
// here code serializes object precisely body advertised calls it: string json = jsonconvert.serializeobject(documents); irestresponse resp = getresponse("https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/keyphrases", taxonomygluekey, json);
message body serializing "documents" is:
{ "documents": [ { "language": "en", "id": "4", "text": "lateral internal sphincterotomy , fissurectomy" }, { "language": "en", "id": "5", "text": "fissurectomy , botox injection" } ]}
i bad request errors. i've verified request sent , passing authentication (it had failed prior). have tried many variations on well.
i able try request body out , works when copying text debug variable directly body provided azure:
if test using above response expected, status 200:
transfer-encoding: chunked x-aml-ta-request-id: c4ea9fff-8068-42a3-99c4-68717acddcf5 x-content-type-options: nosniff apim-request-id: e5eb593b-96a3-4806-9143-1d83424569be date: thu, 21 jul 2016 14:14:44 gmt content-type: application/json; charset=utf-8 { "documents": [ { "keyphrases": [ "fissurectomy" ], "id": "4" }, { "keyphrases": [ "botox injection" ], "id": "5" } ], "errors": [] }
i working jquery
, rest api
sentiment analysis. had received same error have received. managed working providing json-serialized version
of input request body.
here working code-
$(function() { var params ={ "documents": [ { "language": "en", "id": "1", "text": "this awesome!" } ] }; $.ajax({ url: "https://westus.api.cognitive.microsoft.com/text/analytics/v2.0/sentiment?" + $.param( params );, beforesend: function(xhrobj){ // request headers xhrobj.setrequestheader("content-type","application/json"); xhrobj.setrequestheader("ocp-apim-subscription-key","<your subscription key here>"); xhrobj.setrequestheader("accept","application/json"); }, type: "post", // request body data: json.stringify(params) }) .done(function(data) { alert("sentiment score " + data.documents[0].score); }) .fail(function() { alert("error"); }); });
Comments
Post a Comment