0

我需要帮助创建从 xpages 到 yandex Json 接口 api 的 json 请求。如何为此 api 配置 json https 请求。 https://tech.yandex.com/translate/doc/dg/reference/translate-docpage/#codes

或者

如何在 xpages 中使用此块

 URL myURL = new URL(serviceURL);
 HttpURLConnection myURLConnection = (HttpURLConnection)myURL.openConnection();
 String userCredentials = "username:password";
 String basicAuth = "Basic " + new String(new Base64().encode(userCredentials.getBytes()));
 myURLConnection.setRequestProperty ("Authorization", basicAuth);
 myURLConnection.setRequestMethod("POST");
 myURLConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
 myURLConnection.setRequestProperty("Content-Length", "" + postData.getBytes().length);
 myURLConnection.setRequestProperty("Content-Language", "en-US");
 myURLConnection.setUseCaches(false);
 myURLConnection.setDoInput(true);
 myURLConnection.setDoOutput(true); 

像这样的示例代码块

https://translate.yandex.net/api/v1.5/tr.json/translate ? 
key=<API key>
& text=<text to translate>
& lang=<translation direction>
& [format=<text format>]
& [options=<translation options>]
& [callback=<name of the callback function>]
4

2 回答 2

3

最简单的方法是使用无参数构造函数(又名 Bean)将其包装在一个简单的 Java 类中,然后从服务器端 JavaScript 调用它,例如:

var myYandex = new myYandexBean();
myYandex.callServer(somethingtoTranslate);

对于回调,我建议使用休息控件,所以它看起来像 /yournsf.nsf/somepage.xsp/specialName

于 2016-12-11T07:23:07.373 回答
1

除了 Stephan 的回答之外,您还可以使用以下示例的结构创建自己的自定义 REST 服务:https ://stash.openntf.org/projects/DOMEX/repos/dominoexplorer/browse/ODP/Code/Java/net/notesx/ domex/rest/AllDatabasesService.java

于 2016-12-11T20:24:51.020 回答