通过HTTP适配器传递参数? [英] Passing parameters through HTTP Adapter?

查看:153
本文介绍了通过HTTP适配器传递参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在他/她在我的混合应用程序中签名后(基于IBM Worklight 6.0)向用户发送电子邮件。

I want to send an email to the user after he/she sign's up in my hybrid application (based on IBM Worklight 6.0).

我想通过托管的PHP文件的用户参数(电子邮件ID)。我尝试直接在URL中发送邮件作为Follows,这有效:

I want to pass the parameters (email ID) of the user to a PHP file hosted. I tried directly to send a mail in the URL as Follows, and this works:

http://www.xxxyyyzzz.comli.com/email.php?a=someEmailAddress@someEmailHost.com

如何通过Worklight适配器?

How to do the same via a Worklight adapter?

ADAPTER.XML

 <wl:adapter name="sendmail"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xmlns:wl="http://www.worklight.com/integration"
xmlns:http="http://www.worklight.com/integration/http">

<displayName>sendmail</displayName>
<description>sendmail</description>
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>xxxyyy.comli.com</domain>
        <port>80</port> 

        <sslCertificateAlias></sslCertificateAlias> 
        <sslCertificatePassword></sslCertificatePassword>
        -->     
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="getStories"/>

<procedure name="getStoriesFiltered"/>

 </wl:adapter>

ADAPTER IMP.JS

function getStories(interest) {
path = getPath(interest);

var input = {
    method : 'get',
    returnedContentType : 'html',
    path : '/email.php?a='
};


return WL.Server.invokeHttp(input);
}


推荐答案

参数在哪里?您没有将它传递给适配器程序AFAICT。


尝试以下(我没有端到端测试它,因为我没有带有PHP脚本的服务器监听请求)。

Where is the parameter? You are not passing it to the adapter procedure AFAICT.

Try the below (I did not test it end-to-end, as I don't have a server with a PHP script listening to requests).

HTML

Your email address: <input type="text" id="emailaddr"/>
<input type="button" onclick="sendEmail()" value="Submit Email Address"/>

JavaScript

function sendEmail() {
    var invocationData = {
            adapter : 'myAdapter',
            procedure : 'sendEmailProcedure',
            parameters : [$('#emailaddr').val()] // the email adrress taken from the HTML...
    };

    var options = {
            onSuccess : success,
            onFailure : failure
    };

    WL.Client.invokeProcedure(invocationData, options);
}

function success() {
    WL.Logger.debug ("invocation succeeded.");
}
function failure() {
    WL.Logger.debug ("invocation failed.");
}

myAdapter.xml

...
...
<connectivity>
    <connectionPolicy xsi:type="http:HTTPConnectionPolicyType">
        <protocol>http</protocol>
        <domain>host-address</domain>
        <port>80</port> 
    </connectionPolicy>
    <loadConstraints maxConcurrentConnectionsPerNode="2" />
</connectivity>

<procedure name="sendEmailProcedure"/>

myAdapter-impl.js

function sendEmailProcedure(emailAddress) {
    var input = {
        method : 'get',
        returnedContentType : 'html',
        path : '/email.php?a=' + emailAddress
    };

    return WL.Server.invokeHttp(input);
}



查看相关问题:


See related questions:

  • IBM Worklight - How to pass parameters from the application to the adapter?
  • IBM Worklight 6.1 - How to send post values in adapter?

这篇关于通过HTTP适配器传递参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆