Note that there are some explanatory texts on larger screens.

plurals
  1. POMaking a POST call to Google Translate with Jersey returns HTTP 404
    primarykey
    data
    text
    <p>I'm trying to write a POST call to Google Translate with Jersey 1.5. This is my code:</p> <pre><code>package main; import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.WebResource; import com.sun.jersey.core.util.MultivaluedMapImpl; import javax.ws.rs.core.MultivaluedMap; public class Main { private static String GOOGLE_TRANSLATE_URL = "https://www.googleapis.com/language/translate/v2"; private static String translateString(String sourceString, String sourceLanguage, String targetLanguage) { String response; Client c = Client.create(); WebResource wr = c.resource(GOOGLE_TRANSLATE_URL); MultivaluedMap&lt;String, String&gt; params = new MultivaluedMapImpl(); params.add("q", sourceString); params.add("source", sourceLanguage); params.add("target", targetLanguage); params.add("key", "xxxx"); wr.header("X-HTTP-Method-Override", "GET"); response = wr.post(String.class, params); return response; } public static void main(String[] args) { System.out.println(translateString("Hello", "en", "sv")); } } </code></pre> <p>When I run this, all I get back is this: <code>com.sun.jersey.api.client.UniformInterfaceException: POST <a href="https://www.googleapis.com/language/translate/v2" rel="nofollow">https://www.googleapis.com/language/translate/v2</a> returned a response status of 404</code>.</p> <p>I've managed to accomplish this with a simple cURL command like so:</p> <p><code>curl --header "X-HTTP-Method-Override: GET" -d key=xxxx -d q=Hello -d source=en -d target=sv <a href="https://www.googleapis.com/language/translate/v2" rel="nofollow">https://www.googleapis.com/language/translate/v2</a></code></p> <p>Thanks in advance!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload