Getting Image from the server while ignoring the f

2019-08-09 21:59发布

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());                
}

2条回答
劫难
2楼-- · 2019-08-09 22:13

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.
查看更多
Melony?
3楼-- · 2019-08-09 22:26

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...)
查看更多
登录 后发表回答