我正在编写一个 Web 服务,它解析 xml 文件。在客户端中,我将 xml 的全部内容读入字符串中,然后将其提供给 Web 服务。
如果我将 main 作为 Java 应用程序(用于测试)运行 Web 服务,则没有问题,也没有错误消息。但是,当我尝试通过服务器调用它时,出现以下错误:
java.net.MalformedURLException: no protocol
我使用相同的 xml 文件、相同的代码(没有 main),但我只是无法弄清楚错误的原因是什么。
这是我的代码:
DOMParser parser=new DOMParser();
try {
parser.setFeature("http://xml.org/sax/features/validation", true);
parser.setFeature("http://apache.org/xml/features/validation/schema",true);
parser.setFeature("http://apache.org/xml/features/validation/dynamic",true);
parser.setErrorHandler(new myErrorHandler());
parser.parse(new InputSource(new StringReader(xmlFile)));
document=parser.getDocument();
xmlFile 是在客户端构建的:
String myFile ="C:/test.xml";
File file=new File(myFile);
String myString="";
FileInputStream fis=new FileInputStream(file);
BufferedInputStream bis=new BufferedInputStream(fis);
DataInputStream dis=new DataInputStream(bis);
while (dis.available()!=0) {
myString=myString+dis.readLine();
}
fis.close();
bis.close();
dis.close();
如有任何建议,我们将不胜感激!
最佳答案
将协议(protocol) (http) 添加到您的 xmlns:
<user xmlns:xsi="http://w3.org...etc"
关于java - 通过服务器调用 Web 服务会导致 java.net.MalformedURLException : no protocol,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1839351/