标签:
一般来说,大家只会用到GET和POST方法来调用。
比如说server的interface用的是@RequestParam或者@PathVariable,在客户端调用的时候,都可以直接写在URL里,具体写法我就不写了,和下面差不多。
URL = url = new URL(http://test.webservice.api/test);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setRequestProperty("Accept-Charset", "UTF-8");
connection.setRequestProperty("Expect", "100-Continue");
...
DataOutPutStream wr = new DataOutPutStream();
wr.writeBytes("parameter=xxx¶meter2=yyy");
wr.flush();
wr.close();.
....
参考文献http://stackoverflow.com/questions/4205980/java-sending-http-parameters-via-post-method-easily
http://blog.csdn.net/j2ee_me/article/details/8848403
标签:
原文地址:http://www.cnblogs.com/softidea/p/5585588.html