1

Applets 是否有“事实上的”REST 客户端?我需要将杰克逊映射为 JSON 的 POJO 发送到 Spring MVC 控制器。显而易见的选择是 Spring Android,因为它具有功能的缩减版本RestTemplate,但它显然也具有一些特定于确定正在运行的 Android 版本的功能。

有没有简单的方法可以做到这一点?

我尝试过使用“手动”执行此操作HTTPUrlConnection,但我从未在控制器中看到请求出现:

URL url = new URL("http", getDomain(), 8080, getBaseUrl()+"save");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("Cookie", "JSESSIONID=" + getSessionId());

connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod("POST");    
connection.connect();           

OutputStream out = connection.getOutputStream();

mapper.writeValue(out, state);

out.flush();
out.close();
connection.disconnect();
4

0 回答 0