java - 通过服务器调用 Web 服务会导致 java.net.MalformedURLException : no protocol

标签 java web-services url

我正在编写一个 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/

相关文章:

C# 带有 url 参数的简单 web 服务器

ASP.NET 路由(在 WebForms 中)在 IIS 下部署时不工作,但在 IDE 中工作

java - Maven - 生成 Jar 和 War

web-services - ColdFusion中基于REST的网站

java - 非最终初始化程序是线程安全的吗?

java - JAX-WS 是否使用服务器端 stub (骨架)进行通信?

php - 在为网站构建 URL 时,有哪些资源可以帮助您了解最佳实践?

python - 使用 url 编码 python 制作一个简单的 GET/POST

java - 如果字符串 *仅* 包含字符集中的 *所有* 字符,加上一个可选字符,则匹配正则表达式

java - Lucene 不断添加文档,而使用 updateDocument