我如何格式XML输入宁静的Web服务和调用服务

大家好我公开一个服务使用restFul网络服务服务器端代码是

@RequestMapping(value =“/ getPerson”,method = RequestMethod.POST)public ModelAndView getPerson(@RequestParam(“inputXml”)String inputXml){
------------------------- ------------------------- ---
}返回新的ModelAndView(“userXmlView”,BindingResult.MODEL_KEY_PREFIX + String.class,“Test”); }

客户端实现是:

        URL oracle = new URL("http://localhost:8081/testWeb/restServices/getPerson?inputXml=input");
         System.out.println("Oracle URl is "+oracle);
         HttpURLConnection connection = (HttpURLConnection)oracle.openConnection();
         connection.setDoOutput(true);
        connection.setRequestProperty("Content-type", "application/xml; charset:ISO-8859-1");
        connection.setRequestMethod("POST");
        BufferedReader in = new BufferedReader(new InputStreamReader(
                connection.getInputStream()));
        String inputLine;
       while ((inputLine = in.readLine()) != null) 
            System.out.println(inputLine);  
     in.close(); 

我能够使用URL http://localhost:8081/testWeb/restServices/getPerson?inputXml="input"其实我的要求是,我需要传递xml字符串作为输入,像这样

http://localhost:8081/testWeb/restServices/getPerson?inputXml="<?xml%20version="1.0"%20encoding="UTF-8"%20standalone="yes"?><product><code>WI1</code><name>Widget%20Number%20One</name><price>300.0</price></product>"

请帮我找到解决方案


Maya, /getPerson不是RESTful URI名称。 你应该使用类似/person东西。 这样,你可以GET它或使用HTTP DELETE它。


看看RestAssured

given().
       formParam("formParamName", "value1").
       queryParam("queryParamName", "value2").
when().
       post("/something");

或者弹簧RestTemplate

Map<String, String> vars = new HashMap<String, String>();
vars.put("count", "5");
restTemplate.getForObject(person, Person.class, vars);
链接地址: http://www.djcxy.com/p/8607.html

上一篇: How can i format xml input for restful web service and invoke the service

下一篇: Using curl to upload POST data with files