Flutter Image from Arabic URL - flutter

I try:
Image.network("http://ar.latifaonline.com/wp-content/uploads/2022/08/ألبوم-لطيفة-2022.png"),
but that does not work because Arabic characters convert to become :
"http://ar.latifaonline.com/wp-content/uploads/2022/08/%D8%A3%D9%84%D8%A8%D9%88%D9%85-%D9%84%D8%B7%D9%8A%D9%81%D8%A9-2022.png"
and that does not give any image but returns this error:
Exception has occurred.
HttpException (HttpException: Connection closed before full header was received, uri = http://ar.latifaonline.com/wp-content/uploads/2022/08/%D8%A3%D9%84%D8%A8%D9%88%D9%85-%D9%84%D8%B7%D9%8A%D9%81%D8%A9-2022.png)

The reason you get this error is not because of the Arabic characters, is because of http, change it to https and it will work.
if you don't have access to your backend code try this:
String yourUrl =
"http://ar.latifaonline.com/wp-content/uploads/2022/08/ألبوم-لطيفة-2022.png";
yourUrl = yourUrl.replaceFirst('http://', "https://");
Image.network(yourUrl)

Related

Unable to Load image from url in flutter

I am Fetching images from URL and it is providing broken images while on the web the same URL is providing complete and accurate images.
Scheme not starting with alphabetic character
throwing error.
// Depending on where the exception was thrown, the image cache may not
// have had a chance to track the key in the cache at all.
// Schedule a microtask to give the cache a chance to add the key.
Image Url:- https://smott.world/upload/source/1646761765-WhatsApp Image 2022-03-08 at 5.41.29 PM.jpeg
This is happening because your url is not encoded, you can encode using Uri.encodeFull to encode. Encode url will replace white spaces by %20
Example:
var uri = Uri.encodeFull('https://smott.world/upload/source/1646761765-WhatsApp Image 2022-03-08 at 5.41.29 PM.jpeg');
var url = uri.toString();
// url will be "https://smott.world/upload/source/1646761765-WhatsApp%20Image%202022-03-08%20at%205.41.29%20PM.jpeg"
You can see more about percent encoding here

How to include accented characters in Swift URL without percent encoding?

I am trying to make a web request to a URL that needs to keep accented characters instead of percent encoding them. E.g. é must NOT change to e%CC%81. I cannot change this.
These are the allowed characters that shouldn't be percent encoded: AaÁáBbCcDdEeÉéFfGgHhIiÍíJjKkLlMmNnOoÓóÖöŐőPpQqRrSsTtUuÚúÜüŰűVvWwXxYyZz0123456789-
Here is an example of a url I need
https://helyesiras.mta.hu/helyesiras/default/suggest?q=hány%20éves
You can try this url in your web borwser to confirm its working. (The site is in Hungarian.) If you try the proper percent encoded version of this url (https://helyesiras.mta.hu/helyesiras/default/suggest?q=ha%CC%81ny%20e%CC%81ves) then the website will give an error. (Also in Hungarian.)
I have my custom encoder to get this URL string. However to make a web request I need to convert the String to URL.
I tried 2 ways:
URL(string:)
let urlStr = "https://helyesiras.mta.hu/helyesiras/default/suggest?q=hány%20éves"
var url = URL(string: urlStr)
// ERROR: Returns nil
URLComponents with percentEncodedQueryItems
var urlComponents = URLComponents()
urlComponents.scheme = "https"
urlComponents.host = "helyesiras.mta.hu"
urlComponents.path = "/helyesiras/default/suggest"
urlComponents.percentEncodedQueryItems = [ // ERROR: invalid characters in percent encoded query items
URLQueryItem(name: "q", value: "hány%20éves")
]
let url = urlComponents.url
Is it possible to create URLs without Foundation APIs checking its validity? Or can I create my own validation rules?
Safari is percent-encoding the URL. You're just percent-encoding it differently (and in a way your server is rejecting). What Safari sends to the server is:
GET /helyesiras/default/suggest?q=h%C3%A1ny%20%C3%A9ves HTTP/1.1
You can check that using Charles. Your website is behaving correctly and does not appear to require unencoded URLs.
It is not valid to send unencoded URLs, and Safari doesn't. There's no way to do it with URLSession either. You'd have to connect to the socket directly and build your own HTTP stack, which is quite possible, but I don't think you want to do that.
As Leo notes, the correct way to do this is using:
URLQueryItem(name: "q", value: "hány éves")
Replacing the %20 with the unencoded " " so that you don't double-encode the percent.
If you encode the string by hand, you'll find the same encoding:
print("hány éves".addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed))
// Optional("h%C3%A1ny%20%C3%A9ves")
(But you should use URLComponents. addingPercentEncoding is extremely error-prone.)
The preferred UTF-8 encoding of á is as the unicode code point LATIN SMALL LETTER A WITH ACUTE (C3 A1). What you're encoding is LATIN SMALL LETTER A (61) followed by COMBINING ACUTE ACCENT (CC 81). I suspect your server is not applying Unicode normalization rules. While that's unfortunate the fix is simple: use URLComponents, and you'll get the same correct behavior as Safari.

Handle "Invalid hex characters in escape" in tomcat level

Am doing some system testing to URL Sanitation. So I tried rushing the APIs with junk data.Example
http://ipaddress/AppContext/api1?query=%S%n%n%s
If I call this API , my log throws an exception 'Invalid HEX character in escape sequence %n'
How to I catch this in tomcat level and throw a 400 bad request
You can't.
Tomcat doesn't decode the query string until the application requests one or more parameters. The best you can do is write a Filter that always tries to access the query string before the main request processing and returns a 400 response if an exception is thrown.

Send a special parameter via RequestBuilder POST on GWT

I am a beginner of GWT.
In my application, i need to post parameter which of value is a URL such like a following string.
'http://h.com/a.php?code=186&cate_code=MV&album=acce'
As you can see it, it includes character sequences '&cat_code='.
As i know, &parametername=value is form of one parameter!...
Because of this, a PHP file on my server side, only receives a following string,
'http://hyangmusic.com/Ticket_View.php?code=186'
How could i do in this situation... i want to receive a full URL as parameter on the server side PHP.
Please help me.
Thanks in advance.
my code.
String name = "John";
String url = "http://h.com/a.php?code=186&cate_code=MV&album=acce";
String parameter = "name="+name+"&url="+url;
builder.setHeader("Content-Type","application/x-www-form-urlencoded");
builder.sendRequest(parameter,
new RequestCallback() {
}
Use URL.encodeQueryString(url) so that your & is turned into a %26 (26 being the hexadecimal representation of the UTF-8 encoding of &)

Error while reading JSON url in nsstring

i am sending one url to the server
http://ogcitsco.w05.winhost.com/Service.svc/getsubmenu/south indian/restaurant/Lunch
in which i am getting bad url response, since there is one space between two words south indian, how should i work with that, i have tried to remove the space and passed the url however in response getting null value, when i paste the above url into browser it is showing the response
Remember to encode your URL first: [#"http://ogcitsco.w05.winhost.com/Service.svc/getsubmenu/south indian/restaurant/Lunch" stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
a space can be changed to %20 for most languages (or + is possible too i beleve)