0

以下代码返回错误请求异常。不确定这里有什么问题。

     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)
        {


        }
4

1 回答 1

0

您没有对参数(appId、文本、语言)进行编码。你应该做 "..." + WebUtility.UrlEncode(appId) + "..." ...

于 2012-11-25T05:31:45.023 回答