无论如何,您的做法都是不好的做法.您不应该在url中传递json,而json应该用作发布请求的正文.将json作为请求参数并不是真正的REST风格,有人在讨论REST API的url参数是否可以使用,但可以讨论... 编辑带有发布并使用具有数据绑定支持的库的jersey的示例:下载genson库 http://code.google.com/p/genson/,当它在您的类路径中时,json数据绑定将自动启用.定义与json输入(我称为ARequestBean)和AResponseBean对应的类,其中包含将序列化为json的响应.@POST@Path("/post")@Consumes(("application/json") // consumes JSON@Produces("application/json") // sends JSONpublic AResponseBean getJson(ARequestBean request) { return ...;}I am trying to send JSON object as parameter.localhost:8080/HelloWorldApplication/webresources/helloworld/get/{param}During this process I am sending a big JSON object, similar to :{"follow_request_sent": false, "profile_use_background_image": true, "contributors_enabled": false, "id": 200, "verified": false, "profile_image_url_https": "https://si0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "profile_sidebar_fill_color": "e0ff92", "is_translator": false, "profile_text_color": "000000", "followers_count": 869, "profile_sidebar_border_color": "87bc44", "id_str": "200", "default_profile_image": true, "listed_count": 0, "status": {"favorited": false, "contributors": null, "truncated": false, "text": "http://goo.gl/OkfpC", "created_at": "2010-12-07T05:58:01", "retweeted": false, "in_reply_to_status_id": null, "coordinates": null, "source_url": "http://mobile.twitter.com", "source": "Mobile Web", "in_reply_to_status_id_str": null, "in_reply_to_screen_name": null, "in_reply_to_user_id": null, "id": 12023002585628672, "place": null, "retweet_count": 0, "geo": null, "in_reply_to_user_id_str": null, "possibly_sensitive": false, "id_str": "12023002585628672"}, "utc_offset": -28800, "statuses_count": 6, "description": "", "friends_count": 4, "location": "", "profile_link_color": "0000ff", "profile_image_url": "http://a0.twimg.com/sticky/default_profile_images/default_profile_4_normal.png", "notifications": false, "show_all_inline_media": false, "geo_enabled": true, "profile_background_color": "9ae4e8", "profile_background_image_url": "http://a0.twimg.com/images/themes/theme1/bg.png", "name": "Dalbir Singh", "lang": "en", "profile_background_tile": false, "favourites_count": 0, "screen_name": "dalbirsingh", "url": null, "created_at": "2006-04-29T01:00:27", "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme1/bg.png", "time_zone": "Pacific Time (US & Canada)", "protected": false, "default_profile": false, "following": false}my code works well until few number of parameters but not with as large object as mentioned above .Is there any limit to the length of JSONobject or other parameter to be sent over http request , If yes, then how to modify it.Code:@GET @Path("/get/{empno}")// this method process GET request from client @Produces("application/json") // sends JSON public String getJson(@PathParam("empno") JSONObject p) { // empno represents the empno sent from client JSONObject obj = p; String x = obj.toString(); System.out.println(x); //some function return "x"; } 解决方案 Yes there is a limit to urls length. It is however dependent on the browser and the web server (it is usually configurable, but I think it is a bad idea to change it...).Usually if your url is less than 2000 characters it should always work. You can also have a look at this thread What is the maximum length of a URL in different browsers?And some other links maximum length of HTTP GET request?, http://www.boutell.com/newfaq/misc/urllength.html.Anyway what you are doing is a bad practice. You should not pass json in the url, json should be used as the body of post requests. Having json as request parameter is not really REST style, there are discussions if url parameters is ok for REST apis, but it is discutable...EDITAn example for jersey with post and using a library having databinding support:Download genson library http://code.google.com/p/genson/, when it is in your classpath json databinding will be automatically enabled for jersey.Define classes corresponding to the json input (I called it ARequestBean) and AResponseBean containing the response that will be serialized to json.@POST@Path("/post")@Consumes(("application/json") // consumes JSON@Produces("application/json") // sends JSONpublic AResponseBean getJson(ARequestBean request) { return ...;} 这篇关于JAX-RS Web服务使用GET接收的JSON对象的最大长度是多少?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-06 08:59