Re: [Cppcms-users] Cppcms-users Digest, Vol 26, Issue 8
Brought to you by:
artyom-beilis
From: Artyom B. <art...@ya...> - 2011-09-08 17:56:27
|
> Hello,Artyom: My Java developers told me they solved the > cross-domain problem using JSONP. Does CppCMS support it? > I mean JSON_RPC over JSONP. Or do you have any better > idea for this problem? CppCMS Supports JSON-RPC over HTTP via POST requests. So basically that means if you want to implement JSONP you will just to need to handle it on your own. It should be quite trivial to implement with existing JSON support. (See sample below) Now you should remember that: 1. JSONP may expose the application to many security problems. 2. GET requests have limited size this you'll have problems passing big parameters. So it should not be a problem to use but it has no real connection to JSON-RPC. Artyom -------------------------- void main(std::string url) { wrapper_function = request().get("jsonp"); std::string method = request().get("method"); cppcms::json::value params; { std::istringstream params(request().get("params")); if(!v.load(params,true)) { response().make_error_response(503); return; } } response.out() << wrapper_function <<'('; if(method=="sum") sum(v); else if ... response.out() << '); } void sum(json::value const &v) { int x = v[0].number(); int y = v[0].number(); json::value res = x+y; response.out() << res; } ------------- <script src="http://someurl.com/rpc?method=sum&wrapper=parseRequest&parms=[10,20]"></script> |