Android webview does not take bad url - android

WebView does not take url if they are bad formated ??
For example good url format http://www.youtube.com/embed/KeSzOIUJ4xY?rel=0 and
bad url format //player.vimeo.com/video/142545652?badge=0
Is there a way to accept the following bad url as browsers do ??

No android web view didnt take a bad formatted url..
Uri.Builder builder = new Uri.Builder();
builder.scheme("https")
.authority("www."+YOUR_STRING+".com")
.appendPath("turtles")
.appendPath("types")
.appendQueryParameter("type", "1")
.appendQueryParameter("sort", "relevance")
.fragment("section-name");
String myUrl = builder.build().toString();
But you can play with above code.

Related

Use special characters like 'ß' or space in URL

I get an Address via Geocode which looks like this e.g.: "Downing Street, London" and I build an URL String with this address String and other parameters.
This is how i build the url string:
String url = "http://www.friendlyride.at/...?...&enterstring="+enterstring+"&enterlng="+enterLng+"&enterlat="+enterLat+"&exitstring="+exitstring+"&exitlng="+exitLng+"&exitlat="+exitLat+"&info="+infoinput;
enterstring = "Downing Street, London"
Now when I log the URL (which I then call in a JSON AsyncTask with an HTTPDataHandler), the URL is a link (blue) until an 'ß', space or ',' is in the String.
This is the URL in the Android Monitor (Log.d):
http://www.friendlyride.at/...?...&enterstring=Downing Street, London&enterlng=-0.1272206&enterlat=51.5032077&exitstring=Abbey Rd, London&exitlng=-0.1830032&exitlat=51.5367909&info=info
The whole url should be a link (here it breaks at a space). If I enter the Url manually in the browser, it works with spaces and everything.
So how can i use the whole string as url?
If you need any code, please tell me, I'm not sure what code I should include. :)
Your url needs to be encoded to be valid.
For that purpose and greatly improving your code quality as well, I strongly encourage you using Uri.Builder to build your urls :
Uri.Builder builder = new Uri.Builder();
builder.scheme("http")
.authority("www.friendlyride.at")
.appendQueryParameter("enterstring", enterstring)
.appendQueryParameter("enterlng", Long.toString(enterLng))
.appendQueryParameter("enterlat", Long.toString(enterLat));
//Append all your other parameters
String myUrl = builder.build().toString();
This will construct a valid encoded url, like : http://www.friendlyride.at?enterstring=Downing%20Street%2C%20London&enterlng=-0.1272206&enterlat=51.5032077
Note : I do not know what the ...?... part ment in your url, I haven't put it in my answer.

Setting URL in an Android application?

Within my Android application I want to connect to a PHP file on my server/web host. Currently I cannot POST data to the PHP file, I think I am passing the URL in an incorrect format.
Using a Google URL as an example, would this be correct in order to establish the path to my PHP file?
URL url = new URL("http://74.125.224.72/myFile.php");
It seems that you have an extra space in your URL
URL url = new URL("http://74.125.224.72 /myFile.php");
must be
URL url = new URL("http://74.125.224.72/myFile.php");
EDIT You can also use the android Uri class and build it using the Uri.Builder
Uri uri = new Uri.Builder()
.scheme("http")
.authority("74.125.224.72")
.appendPath("myFile.php")
.build();

JsonArrayRequest, url parameter maximum size?

I'm new to android,
I'm using a Json webservice in my app to update some database fields, but I have an issue that I can't figure out.
With this one it's working :
String url2 = "http://www.xxxxxx.com/ParserUpdateUserAction.do?test=[{\"Mail\":\"xxxxxx#hotmail.fr\",\"Nationality\":\"Spain\",\"City\":\"nimes\",\"Quote\":\"b\"}]";
JsonArrayRequest jor = new JsonArrayRequest(url2, new Response.Listener<JSONArray>().....
Not working with this :
String url2 = "http://www.xxxxxx.com/ParserUpdateUserAction.do?test=[{\"Mail\":\"xxxxxx#hotmail.fr\",\"Nationality\":\"Spain\",\"City\":\"nimes\",\"Quote\":\"bla bla bla\"}]";
JsonArrayRequest jor = new JsonArrayRequest(url2, new Response.Listener<JSONArray>().....
Could the URL parameter size be the problem ?
Thanks a lot for your help.
Could be a problem with the spaces - try to use %20 instead of a space
String url2 = "http://www.xxxxxx.com/ParserUpdateUserAction.do?test=[{\"Mail\":\"xxxxxx#hotmail.fr\",\"Nationality\":\"Spain\",\"City\":\"nimes\",\"Quote\":\"bla%20bla%20bla\"}]";
Edit:
There actually is a character limit on GET parameters, but it is about 512, so it shouldn't be a problem here - but you should definitly think of a better solution for longer mails
(Source: Max size of URL parameters in _GET)

How do I call Web Service written in Python from Android app

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.
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

Size limit of a String while posting to server

I am posting a string to server. If string size is up to 6000KB then its posted successfully. But when size exceeded more than this its showing response -1.
I have tried method of posting: syn_data1 is string . records fetch from data base and then appending to A string builder and finally i create synData1 string from String builder
URL url = new URL(syn_data1);
URLConnection urlc = url.openConnection();
HttpURLConnection huc = (HttpURLConnection)urlc;
huc.setRequestMethod("POST");
huc.setConnectTimeout(3000);
huc.connect();
int response = huc.getResponseCode();
I do care about each special character and remove.But I did not get success
In theory, the URI in an HTTP request can be of any length, but the practical limit is on the order of 2k. Please read here for more info on that.
I am assuming the length is coming from the query string parameters (those name=value pairs that come after the ?). You should be putting these in the POST data, leaving the path part of the URI only. Of course, the server will have to be looking for those parameters in the POST data as well.
Are you passing the NameValue pairs properly . This is one successful way which i use .
List<NameValuePair> loginParams = new ArrayList<NameValuePair>(1);
loginParams.add(new BasicNameValuePair("ColumnName In DB",YourString));
then you do
httppost.setEntity(new UrlEncodedFormEntity(loginParams));
and proceed to execute
It's not clear exactly what you're trying to achieve, but this definitely looks wrong:
URL url = new URL(syn_data1.toString());
URLEncoder.encode(syn_data1.toString(),"UTF-16BE");
If syn_data1 is already a string, you don't need to call toString on it.. and calling URLEncoder.encode doesn't have any side-effects, so the second statement is pointless. Perhaps you want:
URL url = new URL(URLEncoder.encode(syn_data1, "UTF-16BE"));
That's just on the encoding side though - you still shouldn't be trying to use enormous URLs. If you have a lot of data, that should be in the body of the request rather than the URL.

Categories

Resources