java - 在 Expresso 中使用客户端代码时出错

标签 java xml http xml-parsing

我上周开始使用 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();

最佳答案

首先,感谢您使用 SXML。我们真的在努力让尽可能多的开发者使用它。

我查看了您的客户端代码,发现缺少一个字段。要使用 Expresso XML 解析器,您需要提供密码。这与您用来登录 GUI 帐户的密码相同。出于安全原因,您的密码不会自动添加到客户端代码中,但您需要它才能连接。

找到代码的一部分

字符串密码 = "";//在这里添加密码

添加您的密码代替空白字符串,然后尝试重新连接。您应该能够连接。

如果您还有其他问题,请告诉我。

劳拉卡瓦纳 www.sxml.com.au

关于java - 在 Expresso 中使用客户端代码时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13084414/

相关文章:

java - IntelliJ 静态 Web 项目到 Tomcat 或 Angular COR

angular - 如何在 Angular 6 同步运行的第一个订阅中使用第二个订阅返回值?

java - 使用 f :event postAddToView 在页面加载后调用 JSF Managed Bean

xml - 如何在 arquillian.xml 中正确地向 ChromeDriver 添加配置文件和扩展

ios - 异步 NSURLConnection 在每个字节之间接收空字节

java - 如何使用 jquery 获取带有换行符的 XML?

http header 的安全性

java - Java 中的 16 位桶式移位

java - 如何配置 ContextLoaderListener 不寻找 applicationContext.xml

java - 安装 jTattoo 主题后如何使框架不装饰