将客户端代码与Expresso一起使用时出现java错误
上周,我在这个网站上看到了expresso paser作为一种解决方案,于是开始使用它(www.sxml.com.au)。我创建了一个免费帐户,登录,上传了一个XML文件并解析了文件。我可以在屏幕上很好地看到结果。然后我用java生成客户机代码并运行它
我使用HTTP运行非SSL版本,从SXML服务器返回了这个错误
还有其他人有这方面的经验吗
请帮助我,因为我需要尽快将其整合到一个项目中
这里是我的客户端代码的一部分,它连接到SXML服务器并发出请求
String username = "adamCoyle";
String password = ""; //ADD PASSWORD HERE
String connectionName = "test1";
String company = "student";
String remoteSXMLURL="http://sxml.com.au:8080/Expresso/RemoteSXML";
/*
* Non- SSL mode
*/
/*
* For SSL mode, uncomment the following code and follow certificate installation instructions in help section
* of website to install the SSL cert into the CA keystore
*/
//String remoteSXMLURL="https://sxml.com.au:8444/Expresso/RemoteSXML";
String urlParams ="";
String fileLocation = "server";
String fileForXMLUpload = "";
if(fileForXMLUpload!="")
{
File xmlFileToBeUploadedFile = new File (fileForXMLUpload);
fileForXMLUpload="";
if(xmlFileToBeUploadedFile.exists())
{
BufferedReader bfr = new BufferedReader(new FileReader (xmlFileToBeUploadedFile));
while(bfr.ready())
{
fileForXMLUpload+=bfr.readLine();
}
}
}
String mode= "all";
String isCached = "false";
String areRulesSimple ="false";
String dynamicParamaters ="";
String sortBy ="";
/* step 2 - make a https connection */
URL sxml = new URL(remoteSXMLURL);
HttpURLConnection yc = (HttpURLConnection) sxml.openConnection();
/* step 3- add the paramaters to the HTTPS connection */
String urlParameters = "username="
+ URLEncoder.encode(username, "UTF-8") + "&password="
+ URLEncoder.encode(password, "UTF-8") + "&connectionName="
+ URLEncoder.encode(connectionName, "UTF-8") + "&company="
+ URLEncoder.encode(company, "UTF-8") + "&fileLocation="
+ URLEncoder.encode(fileLocation, "UTF-8") + "&fileForXMLUpload="
+ URLEncoder.encode(fileForXMLUpload, "UTF-8") + "&mode="
+ URLEncoder.encode(mode, "UTF-8") + "&isCached="
+ URLEncoder.encode(isCached, "UTF-8") + "&areRulesSimple="
+ URLEncoder.encode(areRulesSimple, "UTF-8") + "&dynamicParamaters="
+ URLEncoder.encode(dynamicParamaters, "UTF-8") + "& urlParams ="
+ URLEncoder.encode(urlParams, "UTF-8") + "&sortBy="
+ URLEncoder.encode(sortBy, "UTF-8");
/* step 4- set the properties for the HTTPS connection */
/*
* properties
* requestMethod - The HTTPS request will always be a POST request
* Content-Type - The content type is application/x-www-form-urlencoded
* content-Length - This is the length of the paramaters
*
*/
yc.setRequestMethod("POST");
yc.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
yc.setRequestProperty("Content-Length","" + Integer.toString(urlParameters.getBytes().length));
yc.setRequestProperty("Content-Language", "en-US");
yc.setDoOutput(true);
/* step 5 - push out request to HTTPS server */
DataOutputStream wr = new DataOutputStream(yc.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
# 1 楼答案
首先,感谢您使用SXML。我们正在努力让尽可能多的开发者使用它
我查看了你的客户代码,发现有一个字段缺失。要使用Expresso XML解析器,需要提供密码。这与您登录GUI帐户时使用的密码相同。出于安全原因,您的密码不会自动添加到客户端代码中,但您需要它来连接
找出代码中表示
字符串密码=”//在此处添加密码
添加您的密码代替空白字符串,并尝试再次连接。你应该能够连接
请告诉我您是否还有其他问题
劳拉·卡瓦纳 www.sxml。通用域名格式。au