Problem mit Android-HTTP-POST

Bin ich unter den unten angegebenen code zur Ausführung eines HTTP-POST-request. Die PostData in form einer Zeichenfolge

Stichprobe von PostData:

urn:marlin:breit
band:1-1:registr
ation-service:li
nkAcquisitionurn:
marlin:organizat
ion: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="urn:mar
lin:core:1.0:nem
o:Protokoll:profi
le:1" wsu:Id="si
gid0003" nemosec
:Usage="http://n
emo.intertrust.c
om/2005/10/secur
ity/Profil"/><
/SOAP-ENV:Envelo
pe - >

Erwarten wir eine xml/soap-Antwort, stattdessen bekommen wir eine xml-Datei als Antwort. Kann mir jemand sagen, wenn das Verfahren zu tun, eine HTTP-POST ist korrekt (wie im code unten)

Hinweis: Die gleiche postData verwendet werden, wenn mit cuRL für die Durchführung einer POST ist in Ordnung.

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;
 }  

InformationsquelleAutor santhosh | 2010-11-25

Schreibe einen Kommentar