Getting Image from the server while ignoring the file's case sensitivity

你离开我真会死。 提交于 2019-12-11 04:38:44

问题


How can i make my code to get image "_filename.JPG" not only "_filename.jpg"?

string picUrl = "http://MyServer/" + _filename + ".jpg";            
Image webImage = global::MyProject.Properties.Resources.ImageNotFound1;
try
{
    WebRequest requestPic = WebRequest.Create(picUrl);
    WebResponse responsePic = requestPic.GetResponse();
    webImage = Image.FromStream(responsePic.GetResponseStream());                
}

回答1:


Case sensitivity is enforced by server - your client side code can't influence server's behavior. It is unusual for HTTP servers to require exact casing of the path, but easily obtainable behavior for Unix/Linux based servers and described this way in Uri RFC.

Your options if server is case sensitive:

  • ask for file exact name (possibly server provides a way to get exact file names. I.e. by parsing some HTML page)
  • know casing of the name in advance (i.e. by only using lower-case names on server).
  • generate some/all combinations of case for each character in name (i.e. try known cases like .jpg/ .JPG), but this can take looooong time.
  • reconfigure server to accept file names in non-case way
  • see if server support some sort of hint to do case insensitive file retrieval (unlikely, but...)



回答2:


Like one of Alexei Levenkov suggestions, I made my Apache server case insensitive by enabling a module "mod_speling"

Here is the link http://www.leccionespracticas.com/informatica-sistemas-y-servidores/apache-case-sensitive-to-case-insensitive-and-alias-solved/

Apache is case sensitive on *nix systems, since the underlying file system is case sensitive. This can cause trouble with sites brought over from case-insensitive systems. It is relatively easy to remove that sensitivity with the apache module check_speling (funny name, huh?). It will also remap mistyped urls when possible, mapping index.htm to the proper index.html, etc.

This is the procedure for Ubuntu/Debian systems.

  1. From the command line, type sudo su to get root privileges.
  2. nano /etc/apache2/mods-available/speling.conf
  3. Type CheckSpelling on and hit ctrl-x, y to exit and save the file.
  4. type a2enmod and then speling and hit enter.
  5. type /etc/init.d/apache2 reload to reload apache.
  6. Mistype a url to test it.


来源:https://stackoverflow.com/questions/15329925/getting-image-from-the-server-while-ignoring-the-files-case-sensitivity

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!