简体   繁体   中英

Ignoring 301 Permanent Redirect with NSURLConnection

An API that i'm using that I don't control is using a 301 permanent redirect when it shouldn't be. I need my NSURLConnection to ignore the fact that its been permanently redirected in the past for future requests.

Heres an example for Clarity.

I'm connecting to http://stupidapi.com/users/frank/profilepicture . It does a 301 redirect to http://profilepictures.stupidapi.com/52435346324 which has the profile picture i'm looking for at it.

So lets say that later Frank logs into his account and changes his profile picture. Now when I want the new profile picture I go to http://stupidapi.com/users/frank/profilepicture but since the first request I made was a 301 permanent redirect it sends me back to http://profilepictures.stupidapi.com/52435346324 which is the old picture. If it was my first time requesting it would've sent me to http://profilepictures.stupidapi.com/34535476557 for the new picture.

How do I get NSURLConnection to always go to the newest version of the picture?

I've tried setting the NSURLRequest cache policy to NSURLRequestReloadIgnoringCache

request.cachePolicy = NSURLRequestReloadIgnoringCache;    

I've also tried clearing the NSURLCache before any request is made with

[NSURLCache sharedURLCache] removeAllCachedResponses];

Neither have worked so far. Thanks for any help!

Okay so I figured out a nasty hack of a solution, but its the best I could come up with.

The original URL specified doesn't care about capitalization so basically every time I send a request to it, I randomly set each letter in a specific part of the url to either uppercase or lowercase.

Basically instead of just going to http://stupidapi.com/users/frank/profilepicture I got to http://stupidapi.com/users/FrAnk/profilepicture . If I hit one that hasn't been cached already then I get the new picture.

For my particular use case, this works well enough.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM