Re: [Cppcms-users] Cppcms-users Digest, Vol 26, Issue 8
Brought to you by:
artyom-beilis
|
From: 陈抒 <csf...@gm...> - 2011-09-08 14:06:33
|
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?
陈抒
Best regards
http://blog.csdn.net/sheismylife
On Thu, Sep 8, 2011 at 5:24 PM, 刘怀宇 <mys...@gm...> wrote:
> Thanks for your reply!
> I found out that maybe it is just the Same Origin Policy related errors.
> I used your HTML example ,and deploy it with json_rpc service in one cppcms
> application.
> have a see at my config.js
> {
> "service" : {
> "api" : "http",
> "port" : 8080
> },
> "http" : {
> "script_names" : ["/jsonrpc","/html"]
> }
> }
> We add two applications into cppcms application pool as following:
>
> 1. cppcms::service srv(argc,argv);
> 2.
> srv.applications_pool().mount(cppcms::applications_factory<my_hello_world>() , cppcms::mount_point(std::string(
> "/html")) );
> 3.
> srv.applications_pool().mount(cppcms::applications_factory<json_service>() , cppcms::mount_point(std::string(
> "/jsonrpc")) );
>
> So there are two applications in the same service but different URI.
> I got the response from jsonrpc successfully by this method.
> But if I request the jsonrpc service from another computer by javascript
> ,it doesn't work.
> Is it related to the Same Origin Policy ?
> Is there any method to solve this problem?
>
>
> 2011/9/7 <cpp...@li...>
>
>> Send Cppcms-users mailing list submissions to
>> cpp...@li...
>>
>> To subscribe or unsubscribe via the World Wide Web, visit
>> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>> or, via email, send a message with subject or body 'help' to
>> cpp...@li...
>>
>> You can reach the person managing the list at
>> cpp...@li...
>>
>> When replying, please edit your Subject line so it is more specific
>> than "Re: Contents of Cppcms-users digest..."
>>
>>
>> Today's Topics:
>>
>> 1. Can't get correct response from json rpc server when using
>> javascript (???)
>> 2. Re: Can't get correct response from json rpc server when
>> using javascript (Artyom Beilis)
>>
>>
>> ----------------------------------------------------------------------
>>
>> Message: 1
>> Date: Wed, 7 Sep 2011 16:44:52 +0800
>> From: ??? <mys...@gm...>
>> Subject: [Cppcms-users] Can't get correct response from json rpc
>> server when using javascript
>> To: cpp...@li...
>> Message-ID:
>> <
>> CAM...@ma...>
>> Content-Type: text/plain; charset="iso-8859-1"
>>
>> Hello
>> There is a json rpc example in cppcms project. Now I want to send json_rpc
>> request using javascript , but it doesn't work.
>> I found that the Content-Type field of the HttpRequest message must be
>> "application/json" for cppcms application ,otherwise I got error messages
>> as follows " invalid content type "
>> And I tested successfully by python(in tests dir) and curl command
>>
>> 1.python:
>>
>> def test(name,A,B):
>> if A != B:
>> print "Error :" + name
>> print "-----Actual--"
>> print A,"---Expected--"
>> print B,"-------------"
>> sys.exit(1)
>> else:
>> print "Ok:"+name
>>
>> def test_status(h,stat):
>> if h.status != stat:
>> print "Status mistmatch:",h.status,"!=",stat
>> sys.exit(1)
>>
>> def test_valid(name,params,ans,method='POST'):
>> h=httplib.HTTPConnection('192.168.30.17:8080');
>> headers = {"Content-type": "application/json"}
>> h.request(method,'/rpc',params,headers)
>> r=h.getresponse()
>> test(name,r.read(),ans)
>>
>> test_valid('sum','{"method" : "sum" , "params" : [ 1, 2 ], "id" :
>> 1}','{"id":1,"error":null,"result":3}')
>>
>> 2.curl command:
>> curl -i -X POST --header "Content-Type:application/json" -d
>> '{"method":"sum","params":[1,2],"id":1}' http://192.168.30.17:8080/rpc
>>
>> They both succeeded.
>>
>> But I can't get correct response by using javascript.The following code
>> has
>> been tested in IE8 , Chrome13 and firefox6.It only success in IE8.
>>
>> var xhr = new XMLHttpRequest();
>> var rpcUrl = 'http://192.168.30.17:8080/rpc';
>> var postData = '{"method":"sum","params":[1,2],"id":1}';
>>
>> xhr.open("post", rpcUrl, true);
>>
>> xhr.setRequestHeader("Content-Type","application/json");
>>
>> xhr.onreadystatechange = function() {
>> if (xhr.readyState === 4) {
>> if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
>> alert(xhr.responseText)
>> }
>> }
>> }
>> xhr.send(postData);
>>
>> Maybe the problem is that I can't set the "Content-Type" as
>> "application/json" successfully in Chrome and Firefox.
>>
>> Do you have any experience about ajax?
>> Or just give me an idea!
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>>
>> ------------------------------
>>
>> Message: 2
>> Date: Wed, 7 Sep 2011 03:02:34 -0700 (PDT)
>> From: Artyom Beilis <art...@ya...>
>> Subject: Re: [Cppcms-users] Can't get correct response from json rpc
>> server when using javascript
>> To: "cpp...@li..."
>> <cpp...@li...>
>> Message-ID:
>> <131...@we...>
>> Content-Type: text/plain; charset="utf-8"
>>
>> Actually I don't see any specific reason why wouldn't it work.
>> Are you sure you don't have Same Origin Policy related errors?
>>
>> I've added an HTML example of JSON RPC service in the json_rpc examples
>> directory:
>>
>> ??
>> http://cppcms.svn.sourceforge.net/viewvc/cppcms/framework/trunk/examples/json_rpc/index.html?view=markup
>>
>> ?
>> Artyom Beilis
>>
>>
>>
>> >________________________________
>> >From: ??? <mys...@gm...>
>> >To: cpp...@li...
>> >Sent: Wednesday, September 7, 2011 11:44 AM
>> >Subject: [Cppcms-users] Can't get correct response from json rpc server
>> when using javascript
>> >
>> >
>> >Hello?There is a json rpc example in cppcms project. Now I want to send
>> json_rpc request ?using javascript , but it doesn't work.
>> >?I found that the Content-Type field of the HttpRequest message must be
>> "application/json" for ?cppcms application ,otherwise I got error messages
>> as follows ?" invalid content type "?
>> >And I tested ?successfully by python(in tests dir) and curl command
>> >
>> >
>> >1.python:
>> >
>> >
>> >def test(name,A,B):
>> >? ? if A != B:
>> >? ? ? ? print "Error :" + name?
>> >? ? ? ? print "-----Actual--"
>> >? ? ? ? print A,"---Expected--"
>> >? ? ? ? print B,"-------------"
>> >? ? ? ? sys.exit(1)
>> >? ? else:
>> >? ? ? ? print "Ok:"+name
>> >
>> >
>> >def test_status(h,stat):
>> >? ? if h.status != stat:
>> >? ? ? ? print "Status mistmatch:",h.status,"!=",stat
>> >? ? ? ? sys.exit(1)
>> >
>> >
>> >def test_valid(name,params,ans,method='POST'):
>> >? ? h=httplib.HTTPConnection(' 192.168.30.17:8080');
>> >? ? headers = {"Content-type": "application/json"}
>> >? ? h.request(method,'/rpc',params,headers)
>> >? ? r=h.getresponse()
>> >? ? test(name,r.read(),ans)
>> >
>> >
>> >test_valid('sum','{"method" : "sum" , "params" : [ 1, 2 ], "id" :
>> 1}','{"id":1,"error":null,"result":3}')
>> >
>> >
>> >2.curl command:
>> >?curl -i -X POST --header "Content-Type:application/json" -d
>> '{"method":"sum","params":[1,2],"id":1}' http://192.168.30.17:8080/rpc
>> >
>> >
>> >They both succeeded.
>> >
>> >
>> >But I can't get correct response by using ?javascript.The following code
>> has been tested in IE8 , Chrome13 and firefox6.It only success in IE8.
>> >
>> >
>> >var xhr = new XMLHttpRequest();
>> >var rpcUrl = 'http://192.168.30.17:8080/rpc';
>> >var postData = '{"method":"sum","params":[1,2],"id":1}';
>> >
>> >xhr.open("post", rpcUrl, true);
>> >
>> >xhr.setRequestHeader("Content-Type","application/json");
>> >
>> >xhr.onreadystatechange = function() {
>> >if (xhr.readyState === 4) {
>> >if (xhr.status >= 200 && xhr.status < 300 || xhr.status === 304) {
>> >alert(xhr.responseText)
>> >}
>> >}
>> >}
>> >xhr.send(postData);?
>> >
>> >
>> >Maybe the problem is that I can't set the "Content-Type" as
>> "application/json" successfully in Chrome and Firefox.
>> >
>> >
>> >Do you have any experience about ajax?
>> >Or just give me an idea!
>> >
>> >
>> >
>> >
>>
>> >------------------------------------------------------------------------------
>> >Using storage to extend the benefits of virtualization and iSCSI
>> >Virtualization increases hardware utilization and delivers a new level of
>> >agility. Learn what those decisions are and how to modernize your storage
>> >and backup environments for virtualization.
>> >http://www.accelacomm.com/jaw/sfnl/114/51434361/
>> >_______________________________________________
>> >Cppcms-users mailing list
>> >Cpp...@li...
>> >https://lists.sourceforge.net/lists/listinfo/cppcms-users
>> >
>> >
>> >
>> -------------- next part --------------
>> An HTML attachment was scrubbed...
>>
>> ------------------------------
>>
>>
>> ------------------------------------------------------------------------------
>> Using storage to extend the benefits of virtualization and iSCSI
>> Virtualization increases hardware utilization and delivers a new level of
>> agility. Learn what those decisions are and how to modernize your storage
>> and backup environments for virtualization.
>> http://www.accelacomm.com/jaw/sfnl/114/51434361/
>>
>> ------------------------------
>>
>> _______________________________________________
>> Cppcms-users mailing list
>> Cpp...@li...
>> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>>
>>
>> End of Cppcms-users Digest, Vol 26, Issue 8
>> *******************************************
>>
>
>
>
> ------------------------------------------------------------------------------
> Doing More with Less: The Next Generation Virtual Desktop
> What are the key obstacles that have prevented many mid-market businesses
> from deploying virtual desktops? How do next-generation virtual desktops
> provide companies an easier-to-deploy, easier-to-manage and more affordable
> virtual desktop model.http://www.accelacomm.com/jaw/sfnl/114/51426474/
> _______________________________________________
> Cppcms-users mailing list
> Cpp...@li...
> https://lists.sourceforge.net/lists/listinfo/cppcms-users
>
>
|