I have a URL link like "http://mobile/testing.php?action=2, when i have this link on my IE browser, it will redirect the link to "http://mobile/myimage.jpeg". It directed to my database server folder name, where my the file 开发者_StackOverflow社区I stored called myimage.jpeg.
I am wondering I how can I can put "http://mobile/testing.php?action=2", establish the NSURL connection and let the Xcode learn this path "http://mobile/myimage.jpeg" so that I can extract the image.jpeg and store it into a list where this list can reflect all the files I had in my database.
Anyone can help? would there be any NSURL reference I can use? I did checkup on the pathomponent, but I don know how can I implement it.
If you want to know where it actually gets redirected to, then you'll need to use an asynchronous NSURLConnection
and implement the -[<NSURLConnectionDelegate> connection:didReceiveResponse:]
delegate method.
The NSURLResponse
object passed to that method will actually be an NSHTTPURLResponse
, which means you can:
- Ask it for its
-statusCode
. If the code is a redirection code, then you know your original request was redirected, at which point you can... - Ask it for its
-URL
. This is theNSURL
to which your original request was redirected. From here, you can get its-lastPathComponent
to extract the "myimage.jpeg" bit.
If I've totally misunderstood your question, then you can probably just extract the -path
from your starting URL and get the -lastPathComponent
from that.
精彩评论