1

.Net SOAP サービスに手動でアクセスする必要があります。すべてのインポーターはその WSDL に問題があるため、手動で XML メッセージを作成し、HttpURLConnection を使用して接続し、結果を解析しています。Http/SOAP 呼び出しを、結果を文字列として返す関数にラップしました。ここに私が持っているものがあります:

  //passed in values: urlAddress, soapAction, soapDocument

  URL u = new URL(urlAddress);
  URLConnection uc = u.openConnection();
  HttpURLConnection connection = (HttpURLConnection) uc;

  connection.setDoOutput(true);
  connection.setDoInput(true);
  connection.setRequestMethod("POST");
  connection.setRequestProperty("SOAPAction", soapAction);
  connection.setRequestProperty("User-Agent","Mozilla/5.0 ( compatible ) ");
  connection.setRequestProperty("Accept","[star]/[star]");      
  connection.setRequestProperty("Content-Type", "text/xml; charset=utf-8");

  OutputStream out = connection.getOutputStream();
  Writer wout = new OutputStreamWriter(out);

  //helper function that gets a string from a dom Document
  String xmldata = XmlUtils.GetDocumentXml(soapDocument);
  wout.write(xmldata);        
  wout.flush();
  wout.close();

  // Response
  int responseCode = connection.getResponseCode();
  BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
  String responseString = "";
  String outputString = "";
  //Write the SOAP message response to a String.
  while ((responseString = rd.readLine()) != null) {
      outputString = outputString + responseString;
  }

  return outputString;        

私の問題は、BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));使用しているアドレス (つまり、urlAddress) で「java.io.FileNotFoundException」を取得する行にあります。そのアドレスをブラウザーに貼り付けると、Soap サービスの Web ページが表示されます (アドレスはhttp://protectpaytest.propay.com/API/SPS.svcです)。私が読んだことから、FileNotFoundException は、HttpURLConnection が 400+ エラー メッセージを返す場合です。正確なコードを確認するためだけに getResponseCode() という行を追加したところ、404 でした。他のページから User-Agent ヘッダーと Accept ヘッダーを追加して、それらが必要であると述べましたが、まだ 404 が返されます。

不足している他のヘッダーはありますか? この呼び出しを機能させるには、他に何をする必要がありますか (ブラウザーで機能するため)。

-シュナー

4

0 に答える 0