I'm making Android version of some hebrew website that use WikiEngine but when I try to get some data via it's API using hebrew title names I got wrong answer.
Like if I try to get this URL
http://www.some-web-site.co.il/w/he/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles="HEBREW_TITLE"
I got response from API that title is missing. However if I pass string like this
Blockquote %D7%A1%D7%99%D7%95%D7%A2_%D7%91%D7%A8%D7%9B%D7%99%D7%A9%D7%AA_%D7%9E%D7%9B%D7%A9%D7%99%D7%A8%D7%99_%D7%94%D7%9C%D7%99%D7%9B%D7%94
I got rigth response. This string I got when I copy-paste url from browser. So my question hot can I transfer hebrew topic name to string with this format using Java.
Thanks
Try
String title = "THE_HEBREW_TITLE";
String encodedTitle = URLEncoder.encode(title , "UTF-8");
and use encodedTitle to compose the URL you are using to query the web service.
Related
I am trying to create a String in java with a link in it.
The message reads like
String message ="Something happened please go back to Home and start again";
This message is ultimately encoded using
String msg = URLEncoder.encode(message,"UTF-8");
and displayed on a JSP page, but this message when rendered on JSP page looks like this.
Something happened please go back to Home and start again
Plain String without a actual link in it.
I am not sure how to embed a link in a String message in Java.
This seems a lot like the issue discussed on this link:
https://www.talisman.org/~erlkonig/misc/lunatech%5Ewhat-every-webdev-must-know-about-url-encoding/#Donotuse%7B%7Bjava.net.URLEncoder%7D%7Dor%7B%7Bjava.net.URLDecoder%7D%7DforwholeURLs
The article says:
Do not use java.net.URLEncoder or java.net.URLDecoder for whole URLs
We are not kidding. These classes are not made to encode or decode
URLs, as their API documentation clearly says:
Utility class for HTML form encoding. This class contains static
methods for converting a String to the
application/x-www-form-urlencoded MIME format. For more information
about HTML form encoding, consult the HTML specification.
This is not about URLs. At best it resembles the query part encoding.
It is wrong to use it to encode or decode entire URLs. You would think
the standard JDK had a standard class to deal with URL encoding
properly (part by part, that is) but either it is not there, or we
have not found it, which lures a lot of people into using URLEncoder
for the wrong purpose.
I have formatted the relevant code from the page above and adjusted it with regards to your code:
String pathSegment = "link.com";
String message ="Something happened please go back to Home and start again";
In my Android application I get JSON response string from a PHP url. from the response I get some hotel names with apostrophe, I get ' character instead of apostrophe. How can I parse the hotel with special characters in android? I can see the apostrophe in the browser but could not see in android logcat.
I have tried jresponse = URLEncoder.encode(jresponse,"UTF-8"); but I could not get apostrophe for hotel name.
This is the one of the hotel name in the response.
I see the following in browser.
{"id":12747,
"name":"Oscar's",
....
}
But in the logcat:
id 12747
name Oscar's
Use the decoder instead of encoder. URLDecoder.decode(jresponse,"UTF-8")
Use ISO-8859-2 when you create the URLEncodedEntity that you send off. You can set this as a parameter in the constructor.
Without a specified charset, you are probably sending the data in UTF-8/UTF-16 (most common) which the server is interpreting in a different way.
EDIT: It looks like ISO-8859-2 doesn't support ñ. You may have to change something server-side. http://en.wikipedia.org/wiki/ISO/IEC_8859-2
You can try Html class. eg :-
jresponse = Html.fromHtml(jresponse);
I'm using Jsoup to get html from web sites. I'm using
String url="http://www.example.com";
Document doc=Jsoup.connect(url).get();
this code to get html. But when I use some Turkish letters in the link like this;
String url="http://www.example.com/?q=Türkçe";
Document doc=Jsoup.connect(url).get();
Jsoup sends the request like this: "http://www.example.com/?q=Trke"
So I can't get the correct result. How can I solve this problem?
Working solution, if encoding is UTF-8 then simply use
Document document = Jsoup.connect("http://www.example.com")
.data("q", "Türkçe")
.get();
with result
URL=http://www.example.com?q=T%C3%BCrk%C3%A7e
For custom encoding this can be used:
String encodedUrl = URLEncoder.encode("http://www.example.com/q=Türkçe", "ISO-8859-3");
String encodedBaseUrl = URLEncoder.encode("http://www.example.com/q=", "ISO-8859-3");
String query = encodedUrl.replace(encodedBaseUrl, "");
Document doc= Jsoup.connect("http://www.example.com")
.data("q", query)
.get();
Unicode Characters are not allowed in URLs as per the specification. We're used to see them, because browsers display them in adress bars, but they are not sent to servers.
You have to URL encode your path before passing it to JSoup.
Jsoup.connect("http://www.example.com").data("q", "Türkçe") as proposed by MariuszS does just that
I found this on google: http://turkishbasics.com/resources/turkish-characters-html-codes.php
Maybe u can add it like this:
String url="http://www.example.com/?q=Türkçe";
Document doc=Jsoup.connect(url).get();
I would like to read some html using matlab.
I've already tried urlread but got the url read error
Getting data into MATLAB from HTTPS:
so i tried using java with this:
Handling an invalid security certificate using MATLAB's urlread command.
unfortunately i don't know how to use java with matlab.
so i tried this code and it seems to work
url = 'https://stackoverflow.com/questions/11053664/use-java-in-matlab';
is = java.net.URL([], url ).openConnection().getInputStream();
br = java.io.BufferedReader(java.io.InputStreamReader(is));
str = char(br.readLine());
however i would like to get the whole html page. so i can use regexp.
My kingdom for some help
There is a function in matlab that does that... The name is urlread!
See http://www.mathworks.com/matlabcentral/answers/973
I want a code to search to google engine for songs via zippyshare . For example the keyword will be "inna sun is up zippyshare" and the first result is this url www32.zippyshare.com/v/55151563/file.html . i want to retrieve the code 55151563 from the the 1st result of google.
Thank you in advance
I will not write the code for you, but I can tip you to the right approach.
Get the url using String search = "http://www.google.com/search?hl=en&q=" + string_to_search;
Download the webpage using URL, InputStream and OutputStream. Check this post here.
Read the file and find the first instance of zippyshare.
Here you can read about xml parsing