【问题标题】:Web Service without WSDL [closed]没有 WSDL 的 Web 服务 [关闭]
【发布时间】:2021-10-30 15:38:44
【问题描述】:

我有一个与 Postman 一起使用的 URL,它需要包含用户名和密码。此外,还有 0 伴随的 WSDL。但是,我无法弄清楚在 java 代码中调用它的正确方法。我的用户名和密码已经写了 XHTML 和 Java 来检索用户名和密码。谁能给我一些关于这个过程的指导?

我尝试了以下但没有运气,因为我需要为 APOD 添加一个 maven 依赖项。

// URL
        URL url = new URL("URL");

// Open a connection
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();


        
// This line makes the request
        InputStream responseStream = connection.getInputStream();

// Manually converting the response body InputStream to APOD using Jackson
        ObjectMapper mapper = new ObjectMapper();
        APOD apod = mapper.readValue(responseStream, APOD.class);

// Finally we have the response
        System.out.println(apod.title);

【问题讨论】:

  • 你还没有告诉我们问题是什么。
  • 您尝试访问的 Web 服务的端点 url 是什么?
  • 该 URL 仅生成一个会话 ID,用于进行第二个 Web 服务调用。

标签: java web-services wsdl2java


【解决方案1】:

经过大量研究并浏览互联网后,我找到了最好的方法。使用以下代码,我可以在不使用此 APOD 依赖项的情况下进行调用。

try {
        URL url = new URL("URL");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        connection.setConnectTimeout(5000);
        connection.setReadTimeout(5000);

        int status = connection.getResponseCode();

        if(status > 299){
            reader = new BufferedReader(new InputStreamReader(connection.getErrorStream()));
            while((line = reader.readLine()) != null){
                responseContent.append(line);
            }
            reader.close();
        }else{
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            while((line = reader.readLine()) != null){
                responseContent.append(line);
            }
            reader.close();
        }

       result = responseContent.toString();
    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

我将不得不操作输出以进一步检索第二个输出,但是,没有 WSDL 是解决方案。

【讨论】:

    猜你喜欢
    • 2012-09-11
    • 1970-01-01
    • 2011-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多