SOAP プロトコルを使用して開発されていない Web サービスに XML 要求を送信する必要があります。Web サービスは純粋な XML 要求/応答でのみ機能するため、WSDL はありません。Web サービスは、ダウンロードする必要がある gzip ファイルで応答します。誰でも私を助けてもらえますか?以下のコードから始めました。ありがとう!
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
public class Teste {
public static void main(String[] args)
{
boolean success = XMLDataPost();
System.out.println(success);
}
private static boolean XMLDataPost(){
boolean success = false;
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httpPost = new HttpPost("http://webservice.blablabla.com.br");
StringEntity reqEntity = new StringEntity("<RequestVeiculo><login>02566288000191</login><senha>159828</senha></RequestVeiculo>");
reqEntity.setContentType("text/xml");
reqEntity.setChunked(true);
httpPost.setEntity(reqEntity);
HttpResponse response = httpclient.execute(httpPost);
HttpEntity resEntity = response.getEntity();
if(response.getStatusLine().getStatusCode() == 200){
success = true;
}
if (resEntity != null) {
System.out.println("Tamanho: " + resEntity.getContentLength());
System.out.println("Chunked?: " + resEntity.isChunked());
}
EntityUtils.consume(resEntity);
}
catch (Exception e) {
System.out.println(e);
}
finally {
httpclient.getConnectionManager().shutdown();
}
return success;
}
}