Zimbra offers Open Source email server software and shared calendar for Linux and the Mac
Go Back   Zimbra :: Forums > Zimbra Collaboration Suite > Zimlets

Welcome to the Zimbra :: Forums!
Welcome, if you would like to post a comment please register. We also encourage you to explore all things Zimbra with our team and members of the community.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-24-2010, 09:47 AM
New Member
 
Posts: 4
Default https post from zimlets

Hi,
I'm writting a Zimlets which need to send a http request to a php application. I have written this source code :
PHP Code:
var url "https://app.132.com/my.php";

var 
params "to=" smsParams.to "&msg=" smsParams.body;

var 
reqParam AjxStringUtil.urlEncode(params);
var 
reqHeader = {"Content-Type":"application/x-www-form-urlencoded"};

AjxRpc.invoke(reqParamurlreqHeader, new AjxCallback(thisthis._resultCallback)); 
The PHP code do not receive any parameters.
Is it the right way to do? Is there a way to specify GET or POSt http method?
Thanks
Reply With Quote
  #2 (permalink)  
Old 02-24-2010, 12:01 PM
Zimbra Employee
 
Posts: 105
Default

There is a parameter after the callback on AjxRpc.invoke that specifies "useGET" true/false.

Send via GET:

Code:
var url = "http://www.theurliwanttocall.com";
var response = AjxRpc.invoke(requestData, url, headers, callback, true);
Send via POST:

Code:
var url = "http://www.theurliwanttocall.com";
var response = AjxRpc.invoke(requestData, url, headers, callback, false);

Last edited by sposetti; 02-24-2010 at 12:17 PM..
Reply With Quote
  #3 (permalink)  
Old 02-24-2010, 01:03 PM
Zimbra Employee
 
Posts: 105
Default

One thing to note: calling an external server from zimlet JavaScript is not allowed. This is a cross-domain scripting security limitation imposed by browsers. You can't call from a browser using JavaScript to a server other than the originating server.

However, you can use the Proxy Servlet to get around this security limitation.

1) Call AjxRpc and the URL is the proxy servlet
2) Pass a param for target that is the url + request of the server you want to proxy to.
3) The proxy servlet will take your request, proxy to the external server and send you back the response.

More info on configuring, testing and using the Proxy Servlet can be found here:

ZCS 6.0:Zimlet Developers Guide:Proxy Servlet Setup - Zimbra :: Wiki
Reply With Quote
  #4 (permalink)  
Old 03-01-2010, 08:23 AM
Zimbra Employee
 
Posts: 105
Default

Also added an example that shows calling the Proxy Servlet from a zimlet:

ZCS 6.0:Zimlet Developers Guide:Examples:HTTP GET and POST - Zimbra :: Wiki
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads

Why Join?

Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.

blog.zimbra.com




 

SEO by vBSEO ©2011, Crawlability, Inc.