Error receiving a response to a text translation request at Yandex translator:

HTTP / 1.1 503 SERVICE UNAVAILABLE [Server: nginx / 1.6.2, Content-Type: text / html; charset = utf-8, Content-Length: 0, Connection: keep-alive, Keep-Alive: timeout = 120, X-Content-Type-Options: nosniff, Date: Sun, 16 Oct 2016 09:57:17 GMT] org.apache.http.conn.BasicManagedEntity@4250f136

public String request(String str, String key, String lang) throws Exception{ @SuppressWarnings({ "resource", "deprecation" }) HttpClient client = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(PATH); httpPost.setHeader("User-Agent", "Mozilla/5.0"); List<NameValuePair> params = new ArrayList<>(); params.add(new BasicNameValuePair("key", key)); params.add(new BasicNameValuePair("lang", lang)); params.add(new BasicNameValuePair("format", "html")); params.add(new BasicNameValuePair("text", str)); httpPost.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8)); HttpResponse httpResponse = client.execute(httpPost); BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse .getEntity().getContent(), "UTF-8")); //System.out.println(br.readLine()); String string = br.readLine(); return string; } 

I assume that you need to increase the timeout from the server, but I do not know how. The request is formed correctly as an error occurs only for some texts to be translated.

  • And the fact that the service can actually be unavailable at this moment (which it reports) is not considered? - PinkTux
  • No, because it is always unavailable for a certain text, and if the other is sent, then everything is ok. - user200303
  • And if in other ways to transmit the same text? wget -qO - "https://translate.yandex.net/api/v1.5/tr.json/translate?key=$key&text=$text&lang=ru" - PinkTux
  • I would like more details about where to write with an example. - user200303
  • Yes, just run wget on the command line (if windows - google "wget ​​for windows"), instead of $key - your key, instead of $text - text. It is desirable to add -S to the -qO - parameters. - PinkTux

0