Windows runtime 请求bing microsofttranslate api时出现badrequest错误?
下面的代码返回错误的请求异常。不确定这里出了什么问题Windows runtime 请求bing microsofttranslate api时出现badrequest错误?,windows-runtime,winrt-xaml,winrt-async,Windows Runtime,Winrt Xaml,Winrt Async,下面的代码返回错误的请求异常。不确定这里出了什么问题 string appId = "956vaQc49TdepGpsywiM+BRqfxfgOTeCr/514="; //go to http://msdn.microsoft.com/en-us/library/ff512386.aspx to obtain AppId. string text = "translate this"; string language = "en";
string appId = "956vaQc49TdepGpsywiM+BRqfxfgOTeCr/514=";
//go to http://msdn.microsoft.com/en-us/library/ff512386.aspx to obtain AppId.
string text = "translate this";
string language = "en";
System.Uri uri = new Uri("http://api.microsofttranslator.com/v2/Http.svc/Speak?&appId=" + appId + "&text=" + text + "&language=" + language);
try
{
HttpClient client = new HttpClient();
HttpResponseMessage response = await client.GetAsync(uri);
response.EnsureSuccessStatusCode();
Stream responseBody = await response.Content.ReadAsStreamAsync();
// meTextToSpeeach.Source = uri;
string strResponse;
using (Stream responseStream = responseBody)
{
using (StreamReader sr = new StreamReader(responseStream, System.Text.Encoding.Unicode))
{
strResponse = sr.ReadToEnd();
}
}
}
catch (Exception)
{
}
您没有对参数(appId、文本、语言)进行编码。您应该执行“…”+WebUtility.UrlEncode(appId)+“…”