Working with Azure Machine Learning - Text Analytics REST api, located here. Requires sending a payload to the server via POST. I am trying to get similar results as I do with IBM watson
Here is what I 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 the code that serializes the object to look precisely like 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 from serializing "documents" is:
{
"documents": [
{
"language": "en",
"id": "4",
"text": "Lateral internal sphincterotomy and fissurectomy"
},
{
"language": "en",
"id": "5",
"text": "Fissurectomy and Botox injection"
}
]}
I get Bad Request errors. I've verified my request is sent and passing authentication (it had failed prior). I have tried many variations on this as well.
I am able to try my request body out and it works properly when copying text from debug variable directly to the body provided by Azure:
If I test using the above I get the 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": []
}