Problema con Android HTTP POST
Estoy usando el siguiente código para ejecutar una solicitud HTTP POST. El PostData tiene la forma de una Cadena
Muestra de PostData:
urn: marlin: banda ancha: 1-1: servicio de registro: li nk Adquisición: marlin: organización: testpdc: devi ce-maker-x: clien tnemo: aa08a1: 59e a7e8cfa7a8582http: //docs.oasi s-open. org / wss / 2 004/01 / oasis-200 401-wss-wssecuri ty-utility-1.0.x sd "URI =" urna: mar lin: core: 1.0: nem o: protocolo: perfil: 1 "wsu: Id = "si gid0003" nemosec: Uso = "http: // n emo.intertrust.c om / 2005/10 / secur ity / profile" /> </ SOAP-ENV: Envelo pe>
Esperamos una respuesta xml / soap, en cambio estamos obteniendo un archivo xml como respuesta. ¿Alguien puede decirme si el procedimiento para hacer una POST HTTP es correcto (como en el siguiente código)
Nota: El mismo postData cuando se usa con cuRL para realizar un POST funciona bien.
public byte [] sendRecv(String PostData, long postDataSize){
try{
if(!(PostData.equals("empty"))){
isPost = true;
//InputStream postDataInputStream = new ByteArrayInputStream(postData);
//BasicHttpEntity httpPostEntity = new BasicHttpEntity();
//httpPostEntity.setContent(postDataInputStream);
StringEntity httpPostEntity = new StringEntity(PostData, HTTP.UTF_8);
//httpPostEntity.setContentLength(postData.length);
//httpPostEntity.setContentType("application/x-www-form-urlencoded");
httpPost.setEntity(httpPostEntity);
httpPost.setHeader("Content-Length", new Integer(PostData.length()).toString());
httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded");
httpPost.setHeader("Expect", "100-continue");
}
}catch(Exception e) {
e.printStackTrace();
}
try {
if(isPost == true){
response = mAndroidHttpClient.execute(httpPost);
isPost = false;
}
else {
response = mAndroidHttpClient.execute(httpGet);
}
statusCode = response.getStatusLine().getStatusCode();
if(statusCode != 200 ){
if(statusCode == 404) {
//System.out.println("error in http connection : 404");
//return ERR_HTTP_NOTFOUND
} else if(statusCode == 500){
//System.out.println("error in http connection : 500");
//return ERR_HTTP_INTERNALSEVERERROR
} else {
//System.out.println("error in http connection : error unknown");
//return ERR_HTTP_FATAL
}
}
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
ByteArrayOutputStream bos = new ByteArrayOutputStream();
for (int next = is.read(); next != ENDOFSTREAM; next = is.read()) {
bos.write(next);
}
responseBuffer = bos.toByteArray();
bos.flush();
bos.close();
}catch (IOException e) {
e.printStackTrace();
}
return responseBuffer;
}