拼写API:无法执行http请求 [英] Spell API: unable to do http request
问题描述
我正在尝试使用拼写API,但我无法执行http请求。
I'm trying to use the Spell API but I'm unable to do the http request.
这是我的代码:
使用(var httpClient = new HttpClient (httpClientHandler))
{
httpClient.BaseAddress = new Uri(" https://api.cognitive.microsoft.com");
httpClient.DefaultRequestHeaders.Add(" Ocp-Apim-Subscription-Key",_bingSpellCheckApiKey);
using(var content = new FormUrlEncodedContent(new []
{
new KeyValuePair< string,string>(" Text",text)
})))
{
using(var result =一个等待httpClient.PostAsync(" /bing/v5.0/spellcheck/" ;, content))
{
string resultContent = await result.Content.ReadAsStringAsync();
返回resultContent;
}
}
}
using (var httpClient = new HttpClient(httpClientHandler))
{
httpClient.BaseAddress = new Uri("https://api.cognitive.microsoft.com");
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", _bingSpellCheckApiKey);
using (var content = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("Text", text)
}))
{
using (var result = await httpClient.PostAsync("/bing/v5.0/spellcheck/", content))
{
string resultContent = await result.Content.ReadAsStringAsync();
return resultContent;
}
}
}
但我总能得到这样的答案:
But I always get this answer:
" ; {\" _type \":\" SpellCheck \",\" flaggedTokens \":[]}"
"{\"_type\": \"SpellCheck\", \"flaggedTokens\": []}"
我不明白与https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/56e73036cf5ff81048ee6727/console
I don't understand what is different from the test page at https://dev.cognitive.microsoft.com/docs/services/56e73033cf5ff80c2008c679/operations/56e73036cf5ff81048ee6727/console
谢谢你,Damiano
Thank you, Damiano
推荐答案
什么是你试过的 text
的值? 响应JSON是没有拼写错误时得到的结果。
What are the values of text
you've tried? The response JSON is what you get when there are no spelling errors.
这篇关于拼写API:无法执行http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!