xml
というWebServiceレスポンスを取得するメソッドを作成する必要があります。私はJava
クラスで作成する方法を知っていますが、問題はwebServiceからxml
という応答を得ています。WebServiceレスポンスからXMLとしてレスポンスを取得する方法は?
これらのWebサービスはソープベースです。
ありがとうございます。
xml
というWebServiceレスポンスを取得するメソッドを作成する必要があります。私はJava
クラスで作成する方法を知っていますが、問題はwebServiceからxml
という応答を得ています。WebServiceレスポンスからXMLとしてレスポンスを取得する方法は?
これらのWebサービスはソープベースです。
ありがとうございます。
私はちょうど私の問題を解決しました。 HttpURLConnection
が私を助けます。
次のコードブロックは、java
でMozilla Posterのxml
応答を取得するためのポスターを作成する方法を示しています。
public static void main(String[] args) {
try {
String uri = "http://test.com/IntegratedServices/IntegratedServices.asmx?op=GetUserInfo";
String postData = new XmlTest().xmlRequest("QWERTY10");
URL url = new URL(uri);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true); // This is important. If you not set doOutput it is default value is false and throws java.net.ProtocolException: cannot write to a URLConnection exception
connection.setRequestMethod("POST"); // This is method type. If you are using GET method you can pass by url. If method post you must write
connection.setRequestProperty("Content-Type", "text/xml;charset=UTF-8"); // it is important if you post utf-8 characters
DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); // This three lines is importy for POST method. I wrote preceding comment.
wr.write(postData.getBytes());
wr.close();
InputStream xml = connection.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(xml));
String line = "";
String xmlResponse = "";
while ((line = reader.readLine()) != null) {
xmlResponse += line;
}
File file = new File("D://test.xml"); // If you want to write as file to local.
FileWriter fileWriter = new FileWriter(file);
fileWriter.write(xmlResponse);
fileWriter.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public String xmlRequest(String pin) {
return "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
+ "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n"
+ " <soap:Body>\n"
+ " <GetUserInfo xmlns=\"http://tempuri.org/\">\n"
+ " <pin>" + pin + "</pin>\n"
+ " </GetUserInfo>\n"
+ " </soap:Body>\n"
+ "</soap:Envelope>";
}
私は、これは、応答としてxml
取得したい人に役立ちます願っています。また、私は自分のコードに詳細なコメントを書いた。 SOAP型WebServiceの
:残りの部分については
は、このリンクを見て:
私の質問は解析されていません。私はどのようにXMLとして応答を得ることができるか尋ねました。私は答えとして投稿しました。あなたのお返事ありがとうございます。 –
あなたがこれまでにしようとしているものを共有してください。私たちはあなたを助けてくれるでしょう。 – Veeram
コメントありがとうございました。私はjavaのMozilla Posterのようなメソッドを作りたいと思っています。 –