I have a json file on my server.
http://myserver/myfile.json
If I type the url into a browser I get a page not found error.
If I set the url of a http service to the path of the json file the httpservice wont load it.
Is it possible to load a json file in this way or does the json file have to be the result of a server page request eg: http://myserver/getjson.php
The problem is this:
If I type the URL into a browser I get a page not found error.
It sounds to me like you have a configuration issue on your web server.
There is no way a Flash App can load something from your server that the server itself cannot deliver.
There are two different ways to approach this. You may have to set a mimetype on the server so the file is recognized. Or you may have to define the 'json' extension as an allowable file.
How you go about doing either of those things depends on the web server.
Related
While I'm sure the title could be improved for clarity, my meaning is thus:
When fetching a URL for a file download at http://example.com/dir1/dir2/file.zip, the response code is 200, yet attempting to access http://example.com/dir1, or http://example.com/dir1/dir2, elicits a 404 response code.
Why is this?
URLs don't necessarily correspond to actual directories on the server. Ultimately the path component of a URL is just a name; the server can translate that name to whatever it wants on the back end.
In this case it seems likely that /dir1/dir2/ is a directory on the server, but even so that doesn't mean anything. The server knows about a resource named /dir1/dir2/file.zip, but doesn't know anything about a resource named /dir1.
From https://en.wikipedia.org/wiki/Query_string
A web server can handle a Hypertext Transfer Protocol request either
by reading a file from its file system based on the URL path or by
handling the request using logic that is specific to the type of
resource. In cases where special logic is invoked, the query string
will be available to that logic for use in its processing, along with
the path component of the URL.
What does the quote mean by the two methods by which a web server can handle a HTTP request
"by reading a file from its file system based on the URL path"
"by handling the request using logic that is specific to the type of resource"?
Can you give specific examples to explain the two methods?
Is the query string used in both method?
Thanks.
by reading a file from its file system based on the URL path
^ The web site uses a generic mapping mechanism to convert a URL path to a local filesystem path, and then returns the file located at that path. This is common with static files like .css.
by handling the request using logic that is specific to the type of resource"
^ The web site turns control over to a web application, which contains code written by a developer. The code reads the query string and decides what to do. The logic for deciding what to do is completely customizable, and there does not need to be a static file in the local filesystem that matches the URL.
As part of an imageprocessing module I accept urls in the following format in order to process and cache externally hosted images.
http://localhost:56639/remote.axd/http://ipcache.blob.core.windows.net/source/IMG_0671.JPG?width=400&filter=comic
After processing the file, if I use Response.Redirect(url, false) to redirect the server to a valid external cache url, the server returns a 404 error response citing the StaticFileHandler as the source of the error.
If the file comes from a local source something like.
http://localhost:56639/IMG_0671.JPG?width=400&filter=comic
The server redirects to the external url without issue. Can someone explain why and provide a solution?
Note: remote.axd does nothing other than allow the local server to intercept the external url. I use the .axd extension as it isn't mapped to route by default in MVC.
I've noticed that when looking at the request path the http:// segment is replaced with http:/. I don't know whether that causes an issue.
So the reference to StaticFileHandler is the clue.
Following the actions of my HttpModule the handler is attempting to process the request. When a locally cached file is used this finds the file and all is ok. Since I am redirecting to a remote url and have a remote source the handler is finding nothing and throwing a 404 exception.
Further processing of the request has to be halted following a rewrite using the following method.
HttpApplication.CompleteRequest
I'm using ASP.NET with MVC 2 and have trouble translating a local file url to a server address. It would seem like a fairly simple and common task, but google searches gives me no good answers. (Perhaps i suck at searching)
I have a controller that takes a file from a html form in a view and saves it to disk. I need to return the real url of this file back to the View. Whatever method i use, I always get a string with the local path of the file instead of the http path.
I suspect the url might get translated to http address once the project has been deployed, but I really need the server address when debugging without having to hardcode anything.
Consider the following example in some controller method:
string url = Url.RequestContext.HttpContext.Server.MapPath("~/Content/Files/" + Path.GetFileName(file.FileName));
// outputs: "C:\\Users\\xxx\\Documents\\Visual Studio 2010\\Projects\\[ProjectName]\\Content\\Files\\file.png"
// whereas i'd like something like "http://localhost/Content/Files/file.png" instead
any ideas?
It depends on where you are storing this file. If you are storing it in a directory which is outside of the virtual directory root you won't be able to access it. If the file is inside a folder which is accessible over HTTP you could simply use the Content method:
string url = Url.Content("~/Content/Files/foo.txt");
I am using Flex with Flash player. I know with AIR i can access the file system but i am not using AIR.
Can my application check if a particular file exist when an HTTPService is sent?
The way I solve this problem is to make the request to the server. I then handle the response and check what is in the response. There should be an error in the response if the file was inaccessible.
Although, this could also mean the URL is wrong or that the server refused connection
You can check if a file exists on the local file system using:
import flash.filesystem.*;
var temp:File = File.createTempFile();
trace(temp.exists) // true
temp.deleteFile();
trace(temp.exists) // false
Are you wanting to check if the file exists on the remote machine, the one you are making the HTTP request to?
If you are checking to see if a file exists on the server, it's going to be a server side solution, not a Flex solution. You need some kind of server side scripting language set up (like PHP) that can take the HTTP request, check for the file on the server and then return a response. Should be a pretty easy problem to solve but it has nothing to do with Flex.