Java 将json字符串传递给Post方法

Java 将json字符串传递给Post方法,java,post,http-post,Java,Post,Http Post,我有一个json字符串,我想把它传递给POST方法。但是“execute”和“executeMethod”抛出如下错误: HttpClient类型中的方法execute(HttpUriRequest)不适用于参数(PostMethod)”。我已经包括了依赖关系 我的代码: StringRequestEntity requestEntity = new StringRequestEntity( json-string, "application/js

我有一个json字符串,我想把它传递给POST方法。但是“execute”和“executeMethod”抛出如下错误:

HttpClient类型中的方法execute(HttpUriRequest)不适用于参数(PostMethod)”。我已经包括了依赖关系

我的代码:

StringRequestEntity requestEntity = new StringRequestEntity(
            json-string,
            "application/json",
            "UTF-8");
PostMethod postMethod = new PostMethod("myUrl");
postMethod.setRequestEntity(requestEntity);
HttpResponse response = httpclient.execute(postMethod);
有没有其他方法可以做到这一点?请帮忙。提前谢谢

我用的。 调用post方法的代码段如下所示

String JSON_STRING="{"name":"Example"}";
StringEntity requestEntity = new StringEntity(
JSON_STRING,ContentType.APPLICATION_JSON);
HttpPost postMethod = new HttpPost("http://example.com/action");
postMethod.setEntity(requestEntity);
HttpResponse rawResponse = httpclient.execute(postMethod);

对于ApacheHttpClient,我也遇到了同样的错误,“HttpClient类型的方法execute(HttpPost)未定义”