Java에서 JSON 데이터의 POST를 수행하여 JAX-RS를 테스트하려고합니다.Apache Wink RestClient를 사용하여 JSON 데이터를 웹 서비스에 게시하는 방법은 무엇입니까?
Apache Wink 1.0 및 Apache Wink RestClient를 사용하고 있습니다. docs은 ... 당신이 POST를 수행하는 방법이라고
RestClient client = new RestClient();
Resource resource = client.resource("http://services.co");
String response = resource.contentType("text/plain").accept("text/plain").post(String.class, "foo");
...하지만 난 JSON 데이터를 게시 할 수 있을까요 어떤 변화? "형 클래스 net.sf.json.JSONObject 및 미디어 유형 응용 프로그램/JSON 없음 작가"
JSONObject json = new JSONObject();
json.put("abc", 123);
RestClient client = new RestClient();
Resource resource = client.resource("http://services.co");
JSONObject response = resource.contentType(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_JSON).post(JSONObject.class, json);
...하지만 난 POST에이 오류와 예외가 :
나는이 시도 .모든 아이디어 나 제안을 바랍니다.
롭
에 코드를 내가'.post'이 String.class''하지 것으로 기대하는 것을 제외하고는 지점에 꽤 많이 보이는 따라서 당신은 변경할 수 있습니다 'JSONObject.class'. – Perception
고맙습니다. 'String response = resource.content ... post (String.class, json)'로 변경되었습니다. 이제 클라이언트가 행복해졌습니다. 그러나 새로운 서버 문제가 생겼습니다. 새로운 질문을 추가하고 있습니다. 제발 도와주세요! :) 감사! http://stackoverflow.com/questions/9538342/whats-wrong-with-my-simple-json-jax-rs-web-service –
@Perception - 답글로 의견을 게시하십시오. 올바른 것으로 표시해 드리겠습니다. ! –