2010-06-14 34 views
8

CommuniGate Pro sunucusuyla çalışan mobil uygulama oluşturacağım.HTTP POST isteği nasıl gönderilir ve yanıt alınır?

Örneğin, ben şu Android Müşteri C yapmak gerekir - CGP Sunucu S konuşma ve XIMSS.nonce düğüm değeri elde:

C:GET /ximsslogin/ HTTP/1.1 
    Host: myserver.com 
    Content-Type: text/xml 
    Content-Length: 42 

    <XIMSS><listFeatures id="list" /><XIMSS> 

S:HTTP/1.1 200 OK 
    Content-Length: 231 
    Connection: keep-alive 
    Content-Type: text/xml;charset=utf-8 
    Server: CommuniGatePro/5.3 

    <XIMSS><nonce>2C3E575E5498CE63574D40F18D00C873</nonce><language>german</language><response id="s"/></XIMSS> 
Örnek, ActionScript 3.0'da bu şekilde görünüyor

:

var loader:Loader = new Loader(); 
loader.addEventListener(Event.COMPLETE, completeHandler); 
var urlRequest:URLRequest = new URLRequest(...); 
urlRequest.method = ...; 
urlRequest.data = ...; 
loader.load(urlRequest); 

private function completeHandler(...):void { ... }; 

Android 2.1 için Java'ya nasıl bakacaktır?

+0

Sana anlamlı yardım almak için daha fazla ayrıntı için ihtiyacımız olacak inanıyoruz. –

cevap

18

Schnapple'in söylediği gibi, sorunuz çok geniş gözüküyor ve okumak ve anlamak için kafa karıştırıcı.

İşte bir HTTP POST göndermek ve bir sunucudan yanıt almak için bazı genel kodlar yararlı olabilir.


public String postPage(String url, File data, boolean returnAddr) { 

    ret = null; 

    httpClient.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.RFC_2109); 

    httpPost = new HttpPost(url); 
    response = null; 

    FileEntity tmp = null;  

    tmp = new FileEntity(data,"UTF-8"); 

    httpPost.setEntity(tmp); 

    try { 
     response = httpClient.execute(httpPost,localContext); 
    } catch (ClientProtocolException e) { 
     System.out.println("HTTPHelp : ClientProtocolException : "+e); 
    } catch (IOException e) { 
     System.out.println("HTTPHelp : IOException : "+e); 
    } 
      ret = response.getStatusLine().toString(); 

      return ret; 
} 
+0

Bu yöntemi kullandığımda sunucumdan aldığım yanıt "Resim verilmedi". Bunu nasıl çözebilirim? – includeMe

İlgili konular