There is a specific code that sends a request to the server. I tried to test it in the SOAPUI program works, I try to reach the server through the application, the answer does not come.

private String login(String username, String password) { String xml = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost("https://ololo"); httppost.setHeader("Accept-Encoding", "gzip, deflate"); httppost.setHeader("Content-Type", "text/xml; charset=utf-8"); httppost.setHeader("Host", "oooo"); httppost.setHeader("Expect", "100-continue"); httppost.setHeader("SOAPAction", "http://ololo"); String str = "<soapenv:Envelope \n" + "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" \n" + "xmlns:mob=\"http://ololo">\n" + " <soapenv:Header/>\n" + " <soapenv:Body>\n" + " <mob:Auth>\n" + " <!--Optional:-->\n" + " <mob:authRequisites>\n" + " <!--Optional:-->\n" + " <mob:Login>" + username + "</mob:Login>\n" + " <!--Optional:-->\n" + " <mob:Password>" + password + "</mob:Password>\n" + " </mob:authRequisites>\n" + " </mob:Auth>\n" + " </soapenv:Body>\n" + "</soapenv:Envelope>"; httppost.setEntity(new StringEntity(str)); HttpResponse response = httpclient.execute(httppost); xml = EntityUtils.toString(response.getEntity()/*,"UTF-8"*/); } catch (Exception e) { e.printStackTrace(); } return xml; } 

answer:

  <s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/"> <s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"> <AuthResponse xmlns="http://ololo"> <AuthResult> <ErrorCode>xxx</ErrorCode> <SessionID>00000000000000</SessionID> </AuthResult> </AuthResponse> </s:Body> </s:Envelope> 

Sample request via SOAPUI:

  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mob="http://ololo"> <soapenv:Header/> <soapenv:Body> <mob:Auth> <!--Optional:--> <mob:authRequisites> <!--Optional:--> <mob:Login>xxx</mob:Login> <!--Optional:--> <mob:Password>xxx</mob:Password> </mob:authRequisites> </mob:Auth> </soapenv:Body> </soapenv:Envelope> 

Checked status:

  String status = String.valueOf(response.getStatusLine()); в логах ответ такой: HTTP/1.1 404 Not Found 
  • And can you give an example answer? And where did the code come from, can it be better to remake everything on some ksoap2-android? - Djangorussia
  • @jangorussia, the answer led. the structure of the request was given, I did not hear about ksoap2-android .. - Sergey
  • I go guessing the coffee grounds. Check the SoapAction (header) - maybe the value is wrong, change the ContentType try on application / soap + xml. through which I work here: simpligility.imtqy.com/ksoap2-android/index.html - Djangorussia
  • @jangorussia, I don’t understand at all either, since until recently everything worked, then the logic was redone on the server, and problems started. through SOAPUI, when I tried there without any headers at all, I just sent the request, the only thing I put was wsdl. I just need to understand, maybe the answer from the server is in the wrong encoding? or is it my problem? - Sergey
  • Well, look at the encoding of the response headers. I didn’t work with SOAPUI - I don’t know some subtleties. Judging by the fact that you are not telling a cant from your side, it worked before. Apparently, he is not authorized - and when it worked, did you test the situation if you did not pass authorization? - Djangorussia

1 answer 1

Code for a SOAP request using KSOAP taken from here

 String SOAP_ACTION = "YOUR_ACTION_NAME"; String METHOD_NAME = "YOUR_METHOD_NAME"; String NAMESPACE = "YOUR_NAME_SPACE"; String URL = "YOUR_URL"; SoapPrimitive resultString = null; try { SoapObject Request = new SoapObject(NAMESPACE, METHOD_NAME); addPropertyForSOAP(Request); SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); soapEnvelope.dotNet = true; soapEnvelope.setOutputSoapObject(Request); HttpTransportSE transport = new HttpTransportSE(URL); transport.call(SOAP_ACTION, soapEnvelope); resultString = (SoapPrimitive) soapEnvelope.getResponse(); Log.i("SOAP Result", "Result Celsius: " + resultString); } catch (Exception ex) { Log.e("SOAP Result", "Error: " + ex.getMessage()); } if(resultString != null) { return resultString.toString(); } else{ return "error"; }