java 我在哪里可以放肥皂行动?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10312613/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 00:31:04  来源:igfitidea点击:

where can i Put Soap Action?

javaweb-servicessoap

提问by Venkatasubbaiah Atluru

public class SimpleHTTPRequest {
    String envelope1="<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
    "<soap:Envelope xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:tns=\"urn:insertdata\"" +
    " targetNamespace=\"urn:insertdata\">"+
    "<soap:Body>"+
    "<insertdata>"+
    "<name xsi:type=\"xsd:string\">ghjghj</name>"+
    "<phone xsi:type=\"xsd:string\">1111</phone>"+
    "<email xsi:type=\"xsd:string\">ascom</email>"+
    "<score xsi:type=\"xsd:string\">12</score>"+
    "</insertdata>"+
    "</soap:Body>"+
    "</soap:Envelope>";
    /**
     * @param args
     */
    public static void main(String[] args) {
         String url="http://url/iphone_soap_server.php/insertdata";
          String soapAction="http://urkl/iphone_soap_server.php/insertdata/insertdata";
    HttpURLConnection connection = null;
    OutputStreamWriter wr = null;
    BufferedReader rd  = null;
    StringBuilder sb = null;
    String line = null;
    URL serverAddress = null;
    String data = "width=50&height=100";
    try {
        serverAddress = new URL("http://url/soap-server.php?wsdl");

        connection = null;

        //Set up the initial connection
        connection = (HttpURLConnection)serverAddress.openConnection();

        connection.setRequestMethod("POST");
        connection.setDoOutput(true);

        connection.setDoOutput(true);
        OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());


        writer.write(data);
        writer.flush();




        rd  = new BufferedReader(new InputStreamReader(connection.getInputStream()));
        sb = new StringBuilder();

        while ((line = rd.readLine()) != null)
        {
            sb.append(line + '\n');
        }

        System.out.println(sb.toString());

    } catch (MalformedURLException e) {
        e.printStackTrace();
    } catch (ProtocolException e1) {
        e1.printStackTrace();
    } catch (IOException e2) {
        e2.printStackTrace();
    }
    finally
    {
        //close the connection, set all objects to null
        connection.disconnect();
        rd = null;
        sb = null;
        wr = null;
        connection = null;
    }
}
}

I want consume the soap web services From Java where can i put the Soap Action IN this code... Thanks in Advance.....

我想从 Java 中使用肥皂网络服务,我可以在哪里将 Soap 操作放入此代码中...提前致谢.....

回答by yamen

When using SOAP over HTTP, in general the SOAP Action is inserted in the SOAPActionHTTP header in the request. See the standard here: http://www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528

使用 SOAP over HTTP 时,通常 SOAP 操作会插入SOAPAction到请求的HTTP 标头中。请参阅此处的标准:http: //www.w3.org/TR/2000/NOTE-SOAP-20000508/#_Toc478383528

The SOAPAction HTTP request header field can be used to indicate the intent of the SOAP HTTP request. The value is a URI identifying the intent. SOAP places no restrictions on the format or specificity of the URI or that it is resolvable. An HTTP client MUST use this header field when issuing a SOAP HTTP Request.

SOAPAction HTTP 请求头字段可用于指示 SOAP HTTP 请求的意图。该值是标识意图的 URI。SOAP 对 URI 的格式或特殊性或其可解析性没有任何限制。当发出一个 SOAP HTTP 请求时,一个 HTTP 客户端必须使用这个头域。

So what you want is (assuming soapActionis set to the correct value):

所以你想要的是(假设soapAction设置为正确的值):

connection.setRequestProperty("SOAPAction", soapAction);