[编辑]从breakingpar
Java代码的示例被放置在一个Java库称为GetHTML:
import java.io.*;
import java.net.*;
public class GetHTML {
public String getHTML(String urlToRead) {
URL url; // The URL to read
HttpURLConnection conn; // The actual connection to the web page
BufferedReader rd; // Used to read results from the web page
String line; // An individual line of the web page HTML
String result = ""; // A long string containing all the HTML
try {
url = new URL(urlToRead);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = rd.readLine()) != null) {
result += line;
}
rd.close();
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
}
并用LotusScript使用它:
Uselsx "*javacon"
Use "GetHTML" ' Java library
Const myURL = "http://www.breakingpar.com"
Dim js As JAVASESSION
Dim getHTMLClass As JAVACLASS
Dim getHTMLObject As JavaObject
Dim html As String
Set js = New JAVASESSION
Set getHTMLClass = js.GetClass("GetHTML")
Set getHTMLObject = getHTMLClass.CreateObject
html = getHTMLObject.getHTML(myURL)
我通过这项服务使用这个来填充一个国家的莲花:http://ws.geonames.org/countryInfo?
您可以使用Java代理消费REST服务: Is there an alternative to using the LotusScript GetDocumentByURL method
下面的代码是从技术说明复制。如果请求的是一个更大的脚本柔的部分可以在LS2J
import lotus.domino.*;
import java.net.*;
import java.io.*;
import java.text.*;
import java.util.*;
import java.math.*;
public class JavaAgent extends AgentBase {
public void NotesMain() {
try {
Session session = getSession();
AgentContext agentContext = session.getAgentContext();
Database db = agentContext.getCurrentDatabase();
URL ibmURL = new URL(" http://finance.yahoo.com/q?s=IBM&d=t");
BufferedReader bin = new BufferedReader(new InputStreamReader(ibmURL.openStream()));
String line;
StringBuffer sb = new StringBuffer();
while ((line = bin.readLine()) != null) {
sb.append(line);
}
String ibmString = sb.toString();
Document newNotesDoc = db.createDocument();
newNotesDoc.replaceItemValue("Form", "IBMForm");
newNotesDoc.replaceItemValue("WebPageUS", ibmString);
newNotesDoc.computeWithForm(true, false);
newNotesDoc.save(true, true);
String ibms = newNotesDoc.getItemValueString("QuoteUS");
System.out.println("IBM Raw String is " + ibms);
newNotesDoc.recycle();
NumberFormat n = NumberFormat.getCurrencyInstance(Locale.US);
BigDecimal d = new BigDecimal(ibms);
double ibmd = d.doubleValue();
String ibm = n.format(ibmd);
System.out.println("IBM Currency is " + ibm);
SimpleDateFormat formatter = new SimpleDateFormat("EEEE, MMMM dd, yyyy hh:mm:ss a");
Date currentTime_1 = new Date();
String dateString = formatter.format(currentTime_1);
System.out.println("Formatted date is " + dateString);
String displayText = "IBM stock price as of " + dateString + " NYSE US " + ibm;
System.out.println("Display text is " + displayText);
db.recycle();
} catch (Exception e) {
e.printStackTrace();
}
}
}
嗯包裹HTTP请求,是的,这听起来是正确的,我认为。我会看看是否可以使用相同的方式同时发送一些数据(POST)。谢谢! –