将Microsoft Translator与Java/Jersey/REST一起使用

将Microsoft Translator与Java/Jersey/REST一起使用,java,rest,jersey,language-translation,microsoft-translator,Java,Rest,Jersey,Language Translation,Microsoft Translator,我正在为一个Java项目使用Microsoft Translator,该项目需要Jersey发出HTTP post请求。我当前的代码导致HTTP 400错误-错误请求。我对HTTP非常陌生-有人能给我指出正确的方向吗 Microsoft Access令牌说明: 向令牌服务发送数据时,需要使用application/x-www-form-urlencoded。因此,我将尝试以下方法: com.sun.jersey.api.representation.Form input = new Form()

我正在为一个Java项目使用Microsoft Translator,该项目需要Jersey发出HTTP post请求。我当前的代码导致HTTP 400错误-错误请求。我对HTTP非常陌生-有人能给我指出正确的方向吗

Microsoft Access令牌说明:


向令牌服务发送数据时,需要使用application/x-www-form-urlencoded。因此,我将尝试以下方法:

com.sun.jersey.api.representation.Form input = new Form();
input.add("client_id", "Tyler_Kevin");
input.add("client_secret", "VcwDLMGuFMLnUgqldj.....");
input.add("scope", "http://api.microsofttranslator.com");
input.add("grant_type", "client_credentials");

// send HTTP POST
ClientResponse response = webResource.type("application/x-www-form-urlencoded")
        .post(ClientResponse.class, input);
更新-“应用程序”在webResource.type(“application”…)行中错贴了。修正了它的工作原理。谢谢你的帮助!
com.sun.jersey.api.representation.Form input = new Form();
input.add("client_id", "Tyler_Kevin");
input.add("client_secret", "VcwDLMGuFMLnUgqldj.....");
input.add("scope", "http://api.microsofttranslator.com");
input.add("grant_type", "client_credentials");

// send HTTP POST
ClientResponse response = webResource.type("application/x-www-form-urlencoded")
        .post(ClientResponse.class, input);