java http调用接口书写?

2024-12-19 01:31:52
推荐回答(3个)
回答1:

1、直接用servlet就可以了,request.getInputStream(),然后解析xml,然后你的业务操作,组装XML,response.getOutputStream()写出去就OK了4但这个性能低,而且还要依赖web容器imq2、socket实现http协议,把HTTP协议好好看看,自己解析(其实就是字符串的操作哦)。3、你要是只做客户端的话可以用httpClient284几行代码搞定了

回答2:

rest接口的话可以使用

RestTemplate

String uri = "http://example.com/hotels/1/bookings";

PostMethod post = new PostMethod(uri);
String request = // create booking request content
post.setRequestEntity(new StringRequestEntity(request));

httpClient.executeMethod(post);

if (HttpStatus.SC_CREATED == post.getStatusCode()) {
  Header location = post.getRequestHeader("Location");
  if (location != null) {
    System.out.println("Created new booking at :" + location.getValue());
  }
}

api文档参考http://static.springsource.org/spring/docs/3.1.x/spring-framework-reference/html/remoting.html#rest-client-access

回答3:

你说的我没怎么听懂。http://localhost:8080(tomcat端口号)/项目名称