2014-02-27 16 views
1

Here is my web service code我如何調用從Android應用

用Python編寫的Web服務,我可以使用http://sheltered-taiga-3258.herokuapp.com/toi/<input parameters>我從用戶的Android設備上收集輸入參數我的瀏覽器調用它。顯然,Web服務返回一個JSON數據,我需要在android應用程序的客戶端顯示。我經歷了許多關於android和web服務的帖子和教程,但是並沒有成功,因爲許多人都有PHP中的POST請求和服務的web服務示例。我想爲GET做這件事,服務在燒瓶中。

請幫忙謝謝。

編輯:

我使用HTTPGET對象調用Web服務,我通過我的URL作爲參數傳遞給它。

HttpGet httpget = new HttpGet(myURL); 

,我構建myURL作爲

EditText inputString = (EditText) findViewById(R.id.serverText); 
String appendString =URLEncoder.encode(inputString.getText().toString(), "UTF-8") ; 
private final HttpClient Client = new DefaultHttpClient(); 
String myURL = "http://sheltered-taiga-3258.herokuapp.com/toi/" + appendString; 

在這裏我得到myURL作爲 http://sheltered-taiga-3258.herokuapp.com/toi/hc+stays+toll+collection但我想它以這種方式

http://sheltered-taiga-3258.herokuapp.com/toi/HC%20stays%20toll%20collection%20in%20kolhapur%20city

我知道有一些網址編碼問題BU不知道它的方式。

+1

檢查在[1](HTTP給出的答案的真實的方式://或者[2](http://stackoverflow.com/a/3487413/1833437)或[3](http://stackoverflow.com/a/3286128/1833437)。 –

+0

@ABDC感謝那個似乎在工作的人......會很快嘗試並在此發佈。 –

回答

0

這裏是給我解決我的問題可能不是做了耳根和標準的方式,但讓我出了問題:

String appendString = (inputString.getText().toString()).replace(" ", "%20") ;//here %20 is encoding for space 
String myURL = "http://sheltered-taiga-3258.herokuapp.com/toi/" + appendString; 

這給了我這樣的:

http://sheltered-taiga-3258.herokuapp.com/toi/HC%20stays%20toll%20collection%20in%20kolhapur%20city

代替本

http://sheltered-taiga-3258.herokuapp.com/toi/hc+stays+toll+collection

如果我發現做這件事我一定會在這裏張貼標記爲答案

+0

這真的是一個不好的方式,請參考http://stackoverflow.com/a/3286128/1008278 – VenomVendor

+0

@VenomVendor是的,我當然知道這不是真正的做法......但不知何故解決了我的問題,我會試圖進一步提高它..但如果你檢查我的問題,那麼你會看到我首先嚐試以正常的方式使用'URLEncoder.encode(「URLSTRING」,「UTF-8」)'和給了我不好的結果...... –

相關問題