6
嗨,我有我想學習寧靜services.I創建使用JAX-RS,其如下所示讀取HTTP POST頭
@Path("/users")
public class Welcome {
@POST
@Consumes("text/xml")
@Produces("text/xml")
public Response welcome(String incomingXML){
return Response.status(200).entity("timestamp : " + incomingXML).build();
}
}
我用下面的測試客戶端來測試服務的Web服務故障
public class TestService {
public static void main(String args[]) throws ParserConfigurationException, SAXException, IOException {
ClientConfig config = new DefaultClientConfig();
Client client=Client.create(config);
WebResource service=client.resource(getBaseURI());
String urlString = "http://localhost:8080/JaXRSDemo/rest/users";
URL url = new URL(urlString);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
// set up url connection to get retrieve information back
con.setRequestMethod("POST");
con.setDoInput(true);
// stuff the Authorization request header
byte[] encodedPassword = (userName + ":" + password).getBytes();
con.setRequestProperty("Authorization",encodedPassword.toString());
Customer customer=new Customer();
customer.setName("noobstre");
customer.setPin(123455);
ClientResponse response=service.path("rest").path("users").type(MediaType.APPLICATION_XML).post(ClientResponse.class,customer);
System.out.println(" response " + response.getEntity(String.class));
}
private static URI getBaseURI() {
return UriBuilder.fromUri("http://localhost:8080/JaXRSDemo").build();
}
}
我想在服務器端頭使用的密碼,並做我對着database.The問題查找是我怎麼在服務器讀取頭。
感謝MRDC的暗示! – 2012-03-14 00:48:19