2013-03-22 35 views
0

首先我想能夠發送的HttpResponse與參數,如:Android的XML發送,並得到通過http收到後

http://www.syslang.com/frengly/controller?action=translateREST&src=en&dest=iw&text=good&email=YYY&password=XXX

的代碼看起來是這樣的:

 DefaultHttpClient httpClient = new DefaultHttpClient(); 
     HttpPost httpPost = new HttpPost("http://www.syslang.com/frengly/controller"); 
     List<NameValuePair> pairs = new ArrayList<NameValuePair>(); 
     pairs.add(new BasicNameValuePair("src", "en")); 
     pairs.add(new BasicNameValuePair("dest", "iw")); 
     pairs.add(new BasicNameValuePair("text", "good"));     
     pairs.add(new BasicNameValuePair("email", "YYY")); 
     pairs.add(new BasicNameValuePair("password", "XXX")); 
     UrlEncodedFormEntity entity = new UrlEncodedFormEntity(pairs,HTTP.UTF_8); 
     httpPost.setEntity(entity); 
     HttpResponse response = httpClient.execute(httpPost); 
     HttpEntity httpEntity = response.getEntity(); 

API structure is available at http://www.frengly.com/ (under the API tab)並且共有5個參數(src,dest,text,email,password)。

到目前爲止我每次試圖時間打電話

的HttpResponse響應= httpClient.execute(httpPost); 我不斷收到一個IO異常:(

之後,我應該得到這樣的結構:

-<root> 
    <text>good</text> 
    <translation>טוב</translation> 
    <translationFramed>טוב|</translationFramed> 
    <missing/> 
    <existing>good,</existing> 
    <stat>1/1</stat> 
</root> 

我想我會從這個部分處理建立XML和解析它,因爲我需要

PS:我查 Android, send and receive XML via HTTP POST method 等多個環節,這並沒有幫助我很多

讓我知道。從我的應用程序需要任何代碼行...

在此先感謝。

回答

2

您不需要POST。 您需要取而代之。

// Construct your request here. 
String requestURL= "http://www.syslang.com/frengly/controller?action=translateREST&src=en&dest=iw&text=good&email=YYY&password=XXX" 

DefaultHttpClient httpClient = new DefaultHttpClient(); 
HttpGet httpGet = new HttpGet(requestURL); 
HttpResponse response = httpClient.execute(httpGet); 

而且也是互聯網的權限在AndroidManifest.xml中

<uses-permission android:name="android.permission.INTERNET"/> 
<application 
.... 
.... 
+0

感謝您的快速反應,但仍不能正常工作。在「HttpResponse響應= httpClient.execute(httpGet);」行上引發相同的IO異常行::( – Hades200621 2013-03-22 12:59:54

+1

你添加了互聯網權限? – Calvin 2013-03-22 13:05:55

+0

哦,也許我沒有:(,任何機會,你指導我通過這個,我很可愛的android dev – Hades200621 2013-03-22 13:09:46

相關問題