SHARE
TWEET

Untitled

a guest Feb 18th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Server code:
  2. import javax.ws.rs.GET;
  3. import javax.ws.rs.POST;
  4. import javax.ws.rs.Path;
  5. import javax.ws.rs.core.Context;
  6. import javax.ws.rs.core.Response;
  7.  
  8. import org.apache.http.HttpResponse;
  9.  
  10.  
  11. @Path("/")
  12. public class Server {
  13.     @POST
  14.     @Path("/name")
  15.     public Response name1(@Context HttpResponse response){
  16.         response.setHeader("key","value");
  17.         return Response.ok().header("header",
  18.     response.toString()).entity(/*response*/"name").build();
  19.     }
  20.  
  21. Client side code:
  22.  
  23. import java.io.IOException;
  24. import org.apache.http.Header;
  25. import org.apache.http.HttpResponse;
  26. import org.apache.http.client.ClientProtocolException;
  27. import org.apache.http.client.methods.HttpPost;
  28. import org.apache.http.impl.client.DefaultHttpClient;
  29.  
  30. public class Clinet {
  31.     public static void main(String[] args) throws IOException{
  32.          DefaultHttpClient client = new DefaultHttpClient();
  33.          HttpPost post = new
  34.          HttpPost("http://localhost:8070/FinalTryClientServer15-02-19/name");
  35.          System.out.println(response.getStatusLine());
  36.          response.getAllHeaders();
  37.  
  38.          System.out.println(response.getAllHeaders());
  39.          for(Header s:response.getAllHeaders()){
  40.              System.out.println(s.toString());
  41.          }
  42.       System.out.println("yyy"+response.getEntity().getContent().read());
  43.     }
  44.  
  45.  }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top