2017-10-05 1 views
0

投稿リクエストをURLに送信するために、以下のコードを書きました。コードを実行したとき、私は500のエラーコードを取得しています。しかし、私は下のヘッダーでSOAP UIで同じURLを試してみましたが、私は応答を戻しました。私のコードで何が間違っているのか分かりますか?前もって感謝します。私はヘッダーを正しく追加していないとは思わない。HTTP投稿要求が失敗しました

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:arm="http://siebel.com/Webservice"> 
     <soapenv:Header> 
       <UsernameToken xmlns="http://siebel.com/webservices">username</UsernameToken> 
       <PasswordText xmlns="http://siebel.com/webservices">password</PasswordText> 
       <SessionType xmlns="http://siebel.com/webservices">Stateless</SessionType> 
      </soapenv:Header> 
      <soapenv:Body> 
      <arm:QueryList_Input> 
       <arm:SRNum></arm:SRNum> 
      </arm:QueryList_Input> 
      </soapenv:Body> 
     </soapenv:Envelope> 

以下は私のコードです。

 package com.siebel.Webservice; 

    import java.io.BufferedReader; 
    import java.io.DataOutputStream; 
    import java.io.InputStreamReader; 
    import java.net.HttpURLConnection; 
    import java.net.URL; 

    import javax.net.ssl.HttpsURLConnection; 

    public class HttpQueryList { 
     private final String USER_AGENT = "Mozilla/5.0"; 

     public static void main(String[] args) throws Exception { 

      HttpQueryList http = new HttpQueryList(); 



      System.out.println("\nTesting 2 - Send Http POST request"); 
      http.sendPost(); 

     } 



     // HTTP POST request 
     private void sendPost() throws Exception { 

      String url = "https://mywebsite.org/start.swe"; 
      URL obj = new URL(url); 
      HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); 

      //add reuqest header 
      con.setRequestMethod("POST"); 
      con.setRequestProperty("UsernameToken", "username"); 
      con.setRequestProperty("PasswordText", "password"); 

      String urlParameters = "SWEExtSource=WebService&SWEExtCmd=Execute&WSSOAP=1"; 

      // Send post request 
      con.setDoOutput(true); 
      DataOutputStream wr = new DataOutputStream(con.getOutputStream()); 
      wr.writeBytes(urlParameters); 
      wr.flush(); 
      wr.close(); 

      int responseCode = con.getResponseCode(); 
      System.out.println("\nSending 'POST' request to URL : " + url); 
      System.out.println("Post parameters : " + urlParameters); 
      System.out.println("Response Code : " + responseCode); 

      BufferedReader in = new BufferedReader(
        new InputStreamReader(con.getInputStream())); 
      String inputLine; 
      StringBuffer response = new StringBuffer(); 

      while ((inputLine = in.readLine()) != null) { 
       response.append(inputLine); 
      } 
      in.close(); 

      //print result 
      System.out.println(response.toString()); 

     } 

    } 
+0

これを確認してください:https://stackoverflow.com/questions/14522931/how-to-add-header-to-soap-request –

答えて

1

XMLでは、トークンを指定しています。 SOAP UIを使用してこれを実行すると、私が使用する証明書ファイルがあります。私の場合は、C:\ Program Files(x86)\ SmartBear \ SoapUI-5.2.1 \ binフォルダに入れます。次に、これを使用するSOAP UIを設定しました。あなたは証明書を持っていますか?はいの場合は、それを参照していますか?

+0

私は証明書がありません – James

関連する問題