问题
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.
- From the command line, type sudo su to get root privileges.
- nano /etc/apache2/mods-available/speling.conf
- Type CheckSpelling on and hit ctrl-x, y to exit and save the file.
- type a2enmod and then speling and hit enter.
- type /etc/init.d/apache2 reload to reload apache.
- Mistype a url to test it.
来源:https://stackoverflow.com/questions/15329925/getting-image-from-the-server-while-ignoring-the-files-case-sensitivity