How do I test a @POST method?
It's easy to test @GET because all you need to do is access the URL, how do I do this for @POSTs? Do I need to actually perform a form submit?
Programmatically? Something like this :
String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
// Send data
URL url = new URL("http://hostname:80/urltopostto");
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();
Interactively? You can use SoapUI (the free edition) to do REST Testing
Theres also quite a few REST extensions for Chrome. I use Simple REST Client .
您可以使用rest-client(http://code.google.com/p/rest-client/)之类的工具来测试所有RESTFull WS
The curl tool ( http://curl.haxx.se/ ) is also very useful here.
curl -i -X POST -v --data-urlencode 'key=value' will send a Post with key=value as post data.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.