Я работаю на веб-сайте электронной коммерции, с JSF 2.
Чтобы общаться с компанией, которая выполняет всю операцию с банками, мне нужно отправить этот XML (это просто образец, предоставленный из них): < /p>
1001734898
e84827130b9837473681c2787007da5914d6359947015a5cdb2b8843db0fa832
1603662828
100
986
2010-07-14T15:50:11
PT
visa
A
1
https://www.dummyurl.du/dummypage.do?id ... vnidjfnvmd
1
true
< /code>
Итак, прочитав многое о том, как отправить и XML и получить его, я создаю этот метод: < /p>
public String rent(){
//String folderAndFile = createTransaction();
//creating the HTTP Post
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost("https://qasecommerce.cielo.com.br/servicos/ecommwsec.do");
try {
//Reading the file as an entity
FileEntity entity = new FileEntity(new File("/home/valter.silva/sample.xml"));
entity.setContentType("text/xml");
post.setEntity(entity);
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
< /code>
Но вывод всегда: < /p>
INFO: 001 Requisição inválida
< /code>
Это означает, что мой .xml < /code>, который я отправляю, недействителен. Это по какой -то причине, XML неверен .. но что? Что я могу с этим поделать?//approach v1
public String rent(){
//String folderAndFile = createTransaction();
try {
File file = new File("/home/valter.silva/test.xml");
HttpPost post = new HttpPost("https://qasecommerce.cielo.com.br/servicos/ecommwsec.do");
post.setEntity(new InputStreamEntity(new FileInputStream(file),file.length()));
post.setHeader("Content-type", "text/xml; charset=ISO-8859-1");
//creating the HTTP Post
DefaultHttpClient client = new DefaultHttpClient();
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
//approach v2
public String rent(){
//String folderAndFile = createTransaction();
try {
File file = new File("/home/valter.silva/test.xml");
HttpPost post = new HttpPost("https://qasecommerce.cielo.com.br/servicos/ecommwsec.do");
//creating the HTTP Post
DefaultHttpClient client = new DefaultHttpClient();
String fileInString = fileToString("/home/valter.silva/test.xml");
InputStream inputStream=new ByteArrayInputStream(fileInString.getBytes());//init your own inputstream
InputStreamEntity inputStreamEntity=new InputStreamEntity(inputStream,fileInString.length());
post.setEntity(inputStreamEntity);
HttpResponse response = client.execute(post);
HttpEntity httpEntity = response.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
Подробнее здесь: https://stackoverflow.com/questions/179 ... eb-service