gpt4 book ai didi

java - 我在哪里可以放 SOAP 行动?

转载 作者:行者123 更新时间:2023-12-04 05:49:03 33 4
gpt4 key购买 nike

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;
}
}
}

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

最佳答案

当使用 SOAP over HTTP 时,通常 SOAP Action 被插入到 SOAPAction 中。请求中的 HTTP header 。请参阅此处的标准: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 设置为正确的值):
connection.setRequestProperty("SOAPAction", soapAction);

关于java - 我在哪里可以放 SOAP 行动?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10312613/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com