1

Here is my web service code

I can call it in my browser using http://sheltered-taiga-3258.herokuapp.com/toi/<input parameters> I am collecting Input parameters from user on android device. Obviously web service returns a JSON data which I need to display at client side in android application. I went through many posts and tutorials on android and web service but was not successful as many have the web service example of POST request and service in PHP. I want to do it for GET and service is in flask.

Please help Thank you.

EDIT:

I am calling web service using HttpGet object and I am passing my URL as parameter to it.

HttpGet httpget = new HttpGet(myURL);

and I am Constructing myURL as

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;

Here I am getting myURL as http://sheltered-taiga-3258.herokuapp.com/toi/hc+stays+toll+collection but I want it in this manner

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

I know there is some url encoding problem but dont know way out of it.

Yogesh D
  • 1,663
  • 2
  • 23
  • 38
  • 1
    check the answers given at [1](http://stackoverflow.com/a/573221/1833437) or [2](http://stackoverflow.com/a/3487413/1833437) or [3](http://stackoverflow.com/a/3286128/1833437). – Ab5 Feb 28 '14 at 08:54
  • @ABDC Thanks man that seems to be working...will try it soon and post it here. – Yogesh D Feb 28 '14 at 08:57

1 Answers1

0

Here is what gave me solution to my question may not be the suggestible and standard way of doing it but got me out of the problem:

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

That gave me this :

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

instead of this

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

If I find the authentic way of doing this thing I will surely be posting it here marked as answer

Yogesh D
  • 1,663
  • 2
  • 23
  • 38
  • This is really a bad way of doing it, refer http://stackoverflow.com/a/3286128/1008278 – VenomVendor Mar 01 '14 at 05:22
  • @VenomVendor yes surely I know that is not the authentic way to do it...but somehow solved my problem and I will be looking to improvise it further.. but if you check my question then you will see that I first tried to do it in normal authentic way by using `URLEncoder.encode("URLSTRING","UTF-8")` and gave me bad results... – Yogesh D Mar 01 '14 at 05:39