Why occur error The remote server returned an error: (400) Bad Request. with Microsoft Translator API? RRS feed

  • Question

  • This is my code call Microsoft Translator API.

     Dim admToken As AdmAccessToken
                Dim admAuth = New AdmAuthentication("myapp", "BHynvBofeqdklsfdksfladsklssfas=")
                admToken = admAuth.GetAccessToken()
                Dim authToken = "Bearer" + " " + admToken.access_token
                While worksheetUser.Cells(iRow, 1) IsNot Nothing
                    If worksheetUser.Cells(iRow, 2).value <> "" Then
                        Dim strSentence = worksheetUser.Cells(iRow, 2).value
                       'Microshop translator api                   
                        Dim uri = "http://api.microsofttranslator.com/v2/Http.svc/Translate?text=" + System.Web.HttpUtility.UrlEncode(strSentence) + "&from=" + g_strSRC_LANG + "&to=" + g_strDES_LANG
                        Dim httpWebRequest = WebRequest.Create(uri)
                        httpWebRequest.Headers.Add("Authorization", authToken)
                        Dim response = httpWebRequest.GetResponse()
                    End If
                    iRow = iRow + 1
                End While

    first sentence: translate ok.

    second sentence: occur error The remote server returned an error: (400) Bad Request.

    Monday, September 26, 2016 1:03 PM

All replies

  • Hi daitran,

    According to your description, it works well first time. it seems that the code is fine. please check if you pass invalid parameters, which cause the issue.

    In addition, this forums is to discuss about data platform development using ADO.NET DataSet and LINQ to DataSet, As your issue is not related to DataSet, we'll move it to Off-Topic forum.

    Thanks for your understanding.

    Best regards,

    Cole Wu

    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, September 27, 2016 4:55 AM
  • My sentence very simple:



    Tuesday, September 27, 2016 7:10 AM