title: Send SOAP with Groovy or Java
body: <p>I've red and try the multiples SOAP messages. I've tried to paste them in my solution but no way of getting the answer.</p>
  
  <p>I use this Groovy code to send SOAP request and get SOAP answer. And it works for 2 web services. I used SoapUI to write my XML and the XML I use here is working on SoapUI, I get the answer from the server.</p>
  
  <p>Now my working XML and my working Groovy script (for other services) are not working together and I don't know how is the problem. I'm not a dev. I've got a SSL error but I'm sure there is no SSL certificate on this server and with SoapUI without SSL it's working and the provider told me there is no certificate to have.</p>
  
  <p>Can you help me and see where is the problem ? Thanks a lot in advance.<br>
  Kind regards.
  Antoine</p>
  
  <p>The Groovy script :</p>
  
  <pre><code>// Send data
  URL url = new URL(url);
  HttpURLConnection conn = url.openConnection();
  conn.setDoOutput(true);
  if( soapaction != null ) conn.setRequestProperty( "SOAPAction", soapaction );
  conn.setRequestProperty( "Content-Type", "text/xml" );
  String authorizationString = "Basic " + (username + ":" +  password).bytes.encodeBase64();
  conn.setRequestProperty ("Authorization", authorizationString);
  OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
  wr.write(xml);
  wr.close();
  
  // Get the response
  String response;
  InputStream responseStream;
  try {
      responseStream = conn.getInputStream();
      success = 1;
  } catch( IOException e ) {
      success = 0;
      if( conn.getResponseCode() == 500 ) {
          responseStream = conn.getErrorStream();
      } else throw e;
  }
  response = responseStream.getText("utf-8");
  responseStream.close();
  return response;
  </code></pre>
  
  <p>Some parameter for this script:<br>
  XML<br>
  soapaction : getAnimals<br>
  URL :<a href="https://test.anis.ch/HTDB.WebService/AnimalImportService.asmx" rel="nofollow">https://test.anis.ch/HTDB.WebService/AnimalImportService.asmx</a><br>
  password : test<br>
  username : 613731</p>
  
  <p>The XML:</p>
  
  <pre class="lang-xml prettyprint-override"><code>&lt;soapenv:Envelope xmlns:soapenv="http://schemas.xmlso.../soap/envelope/" xmlns:urn="urn:tvd:heimtierdatenbanksql:webservice:animalimportmessages:v1" xmlns:urn1="urn:tvd:heimtierdatenbanksql:webservice:animalimportdata:v1"&gt;
     &lt;soapenv:Header/&gt;
     &lt;soapenv:Body&gt;
        &lt;urn:getAnimals&gt;
           &lt;urn:getMessage&gt;
              &lt;urn1:Header&gt;
                 &lt;urn1:P_Praxisnummer&gt;371066&lt;/urn1:P_Praxisnummer&gt;
                 &lt;urn1:P_Account&gt;613731&lt;/urn1:P_Account&gt;
                 &lt;urn1:P_PIN&gt;test&lt;/urn1:P_PIN&gt;
              &lt;/urn1:Header&gt;
              &lt;urn1:Body&gt;
                 &lt;!--1 or more repetitions:--&gt;
                 &lt;urn1:KZ_Kennzeichnung&gt;756000100230345&lt;/urn1:KZ_Kennzeichnung&gt;
              &lt;/urn1:Body&gt;
           &lt;/urn:getMessage&gt;
        &lt;/urn:getAnimals&gt;
     &lt;/soapenv:Body&gt;
  &lt;/soapenv:Envelope&gt;
  </code></pre>