Public String Myrequest () throws IOException, urisyntaxexception{
String url= "Http://localhost:8080/testspring/myResponse";
Clienthttprequest request = new Simpleclienthttprequestfactory (). Createrequest (new URI (URL), httpmethod.post);
Request.getheaders (). Set ("Content-type", "APPLICATION/JSON;CHARSET=GBK");
String json = "{\" name\ ": \" monkey\ ", \" password\ ": \" 1234\ "}";
Request.getbody (). Write (Json.getbytes ("GBK"));
Clienthttpresponse response = Request.execute ();
InputStream is = Response.getbody ();
Byte[] B = new byte[(int) response.getheaders (). Getcontentlength ()];
Is.read (b);
string s = new string (b, "GBK");
System.out.println (s);
return null;
}
The URI here must be in absolute path.
Media Format online self-Baidu
public void Myresponse (HttpServletRequest request,httpservletresponse response) throws ioexception{
InputStream is = Request.getinputstream ();
byte[] bytes = new Byte[request.getcontentlength ()];
Is.read (bytes);
String string = new String (bytes,request.getcharacterencoding ());
System.out.println (string);
Response.getwriter (). Write ("Success");
}
Spring's self-built request requests