简体   繁体   中英

Google Translate API How to translate big text ((414) Request-URI Too Large) with .NET library

I am using .NET library http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Translate_API for translating texts, but I can't translate big texts, just small one.

I am getting error (414) Request-URI Too Large. There should be some way how to do this.

I have this code

        var service = new TranslateService();
        service.Key = this.ApiKey;

        var request = service.Translations.List(textToTranslate, this.LngDestination);
        request.Source = this.LngSource;

        TranslationsListResponse response = request.Fetch();

        foreach (TranslationsResource translation in response.Translations)
        {
            return translation.TranslatedText;
        }

Does someone know how to solve this problem?

The documentation for this project says,

Note: You can also use POST to invoke the API if you want to send more data in a single request. The q parameter in the POST body must be less than 5K characters. To use POST, you must use the X-HTTP-Method-Override header to tell the Translate API to treat the request as a GET (use X-HTTP-Method-Override: GET).

If you want help switching to POST , include the relevant code from your TranslateService() object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM