Web服务 – REST服务 – 在浏览器中测试PUT方法

前端之家收集整理的这篇文章主要介绍了Web服务 – REST服务 – 在浏览器中测试PUT方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我开发了REST服务.我可以通过浏览器或客户端应用程序测试GET方法.但是那些有PUT方法的人我不知道如何通过浏览器来消费它们……

例如,在插入userId之后,我有这个方法打开灯:

  1. @PUT
  2. @Path("/lampon")
  3. @Produces({"application/json","text/plain"})
  4. @Consumes("multipart/form-data")
  5. public boolean turnOnLamp(@FormParam("userId") String userId) throws Exception
  6. {
  7. boolean response = new LampManager().turnOnLamp(userId);
  8. return response;
  9. }

在我的客户端应用程序中,我这样做,它的工作原理:

  1. String webPage = "http://localhost:8080/BliveServices/webresources/services.actuators/lampon";
  2.  
  3. URL urlToRequest = new URL(webPage);
  4.  
  5. //Authentication
  6.  
  7. urlConnection = (HttpURLConnection) urlToRequest.openConnection();
  8. urlConnection.setReadTimeout(10000);
  9. urlConnection.setConnectTimeout(15000);
  10. urlConnection.setRequestMethod("PUT");
  11. urlConnection.setRequestProperty("Authorization",basicAuth);
  12. urlConnection.setRequestProperty("Content-type","multipart/form-data");
  13. urlConnection.setRequestProperty("Accept","application/json");
  14. urlConnection.setDoOutput(true);
  15. urlConnection.setDoInput(true);
  16.  
  17. List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
  18. nameValuePairs.add(new BasicNameValuePair("userId","2"));
  19.  
  20. (...)

但是如何通过浏览器发送userId呢?

另一件事,我在构建项目时收到此消息:

  1. SEVERE: Resource methods utilizing @FormParam and consuming "multipart/form-data" are no longer supported. See @FormDataParam.

谢谢

解决方法

如果要使用浏览器测试REST-Webservice,则必须安装插件.

如果您使用谷歌浏览器,您可以安装REST控制台我也使用这些插件来测试我的Web服务.

https://chrome.google.com/webstore/detail/rest-console/cokgbflfommojglbmbpenpphppikmonn

对于Firefox安装这些REST-Client

https://addons.mozilla.org/en-us/firefox/addon/restclient/

REST CLient也可用于Safari
http://restclient.net/

对于Opera,您可以查看Simple REST-Client

https://addons.opera.com/en/extensions/details/simple-rest-client/

对于你的第二个问题

请尝试消费价值’application / x-www-form-urlencoded’

猜你在找的HTML相关文章