2011-05-09 11 views
0

我不是經驗豐富的Java和我得到了一些XML的交互工作示例代碼,我唯一的問題是,我需要發佈的數據(用戶名/密碼)將Java爲例,POST

相關代碼:

static String myUrlString = "http://www.grupoandroid.com/interface/mobile/index.php"; 
protected TheParser(){ 
    try { 
     this.myUrl = new URL(myUrlString); 
    } catch (MalformedURLException e) { 
     throw new RuntimeException(e); 
    } 
} 



protected InputStream getInputStream() { 
    try { 
     return myUrl.openConnection().getInputStream(); 
    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } 
} 
+0

該代碼似乎與您的問題的要求無關 - GET在哪裏?我不明白XML交互的代碼如何幫助你 - 它是否讀取或寫入服務器的XML? – 2011-05-09 01:15:49

回答

1

可以使用HttpURLConnection

protected InputStream getInputStream() { 
    try { 
     HttpURLConnection con = new HttpURLConnection(myUrl); 
     con.setRequestMethod("POST"); 
     //writeout data to the output stream 
     return con.getInputStream(); 
    } catch (IOException e) { 
     throw new RuntimeException(e); 
    } 
} 
0

我想你最好不要使用HTTP客戶端庫,而不是解析完整的HTTP堆棧自己。

apache-http-client
hotpotato

你可以找到在網上對這些足夠的例子和教程。

+0

尤其是,由於apache http庫已經包含在android運行時。 – Stephan 2011-05-09 11:30:01