WKWebView doesn't follow redirects - wkwebview

If I load a URL in a browser, it redirects (there is a 302 code in Charles). When a WKWebView loads the same URL, it doesn't - it's just a 200.
Is there a way to get WKWebView to follow HTTP redirections? Do I need to override some method in maybe the navigation delegate?

Related

How to intercept or pause http status code 301 request in a browser

I am looking for a solution to interrupt or pause a 301 ( redirect ) request in Chrome dev tools. My scenario is I have an API integration with a local payment gateway which requires 301 redirect to their server ( HTTP GET and then redirect with 301 to an external URL). As 301 HTTP status code happens on the client-side so this can be compromised as the current system does not protect the integrity of the data, for instance, the amount to pay. I might send 100$ and the user might change it to 20$.
To prove this I need to stop the request manually which is very inconvenient and hard to test. I am looking for a solution that implements in one of my favorite browsers above that allows me to config to interrupt or pause the 301 HTTP status code so I can easily modify the value in the URL before resuming the request.
I found a chrome extension to solve this issue.
Requestly is easy to use and test. This is what being mentioned in the extension page:
Chrome Extension to modify HTTP requests (Setup Redirects, Run Custom
Javascript, Modify Headers
But my scenario is about modifying url query string - not being mentioned in the description but it works perfectly.

How to disable caching of 301 responses in an extension for specific domains

I'm working on a Chrome extension that detects and redirects certain domains, but when the origin server sends a 301 redirect, the cached response interferes with detecting whether I should perform my own redirect on subsequent requests. I need the extension to prevent the browser from caching the redirect.
I've looked into the onHeadersReceived event, as this seems to be the first event that fires after we get the 301 response, but that event fires after caching directives are received, and won't prevent the response from being cached.
If you're having a hard time with a 301 redirect on your website never changing on your browser, even using the network -> Disable cache (while DevTools is open) with dev tools open. Try in DevTools to put in the console: $.get(“https://redirect.url.com/page”) which returned the post response as 200. Check this blogpost for more details.

Getting redirected URL in python 3

I want to get the address of a page after redirect. I have the following code
url = 'https://simple.wikipedia.org/wiki/Gcd'
print(urlopen(url).geturl())
But it doesn't work, it prints https://simple.wikipedia.org/wiki/Gcd, while it should print https://simple.wikipedia.org/wiki/Greatest_common_divisor.
So, what is the problem with it?
There is actually no problem. The URL you get when opening https://simple.wikipedia.org/wiki/Gcd is exactly that URL. The only way for the URL to change would be a redirect, and if you look at the response from that URL, you can see that it returns just a 200 status code. So there is no redirect.
However, when you open the URL in the browser, the URL does get changed to https://simple.wikipedia.org/wiki/Greatest_common_divisor. How does this happen when there is no redirect?
This is actually a new MediaWiki feature that rewrites the URL in the browser using the History API. It simply replaces the URL that is displayed in the browser—but without actually making a new request or being a true HTTP redirect.
It’s a functionality that only works in modern browsers with JavaScript enabled. Otherwise, you would stay on the Gcd URL which is also the behavior from older versions of MediaWiki.
You can learn more about this new MediaWiki feature in the Phabricator task T37045.
As for your “problem” with it, you should consider communicating with MediaWiki using the MediaWiki API which will also tell you when a page is a redirect.

Origin not allowed by Access-Control-Allow-Origin with TYPO3 FE-Login

I've been looking at plenty solutions for the "Origin http://example.com is not allowed by Access-Control-Allow-Origin" but I couldn't fix mine.
There is an admin area where you need to log in to view the page. When you hit the submit button, nothing happens. Looking into the console, it throws following error:
XMLHttpRequest cannot load
http://www.example.com/index.php?eID=FrontendLoginRsaPublicKey. Origin
http://example.com is not allowed by Access-Control-Allow-Origin.
I've literally added an Access-Control-Allow-Origin wildcard in every .htaccess I could find, but without effect. Does anyone has a solution for this issue?
I just had the same issue. The wrong XMLHttpRequest was related to the config.baseURL which pointed to https://www.domain.ltd.
When you open the page with http://www.domain.ltd/loginpage.html the login process will not work, because the asynchron request is send to the https version of this page. I set the login page to https (settings > behaviour > protocol), so typo3 will do a 301-forward if the user hits the non https version.
Now the login is working without any errors.
Also make sure that you access the page with the domain registered in baseURL. If you access http://domain.ltd/loginpage.html and http://www.domain.ltd/ is set in baseURL the error occurs too.
Have you tried the new jsonp ?? into your ajax request.
dataType: "jsonp",
jsonpCallback: "localJsonpCallback"
Here is an example: https://www.sitepoint.com/jsonp-examples/

htaccess redirect to anchor properly but doesn't rename

Currently I have this:
RewriteRule ^Skills$ http://mypage/resume.php#Skills [NE,NC,L]
Which redirects properly to the anchor link when I have the url: http://mypage/Skills.
However the URL in the browser shows the actual anchor link: http://mysite/resume.php#Skills
Instead of showing me http://mysite.com/Skills
How can I redirect and rewrite the url?
It is redirecting the browser because you have an http://mypage in front of your RewriteRule target. This automatically tells the rewrite engine you want a 302 redirect so the address bar of your browser is going to be changed. However, the problem here is if you remove it so that it's just /resume.php#Skills, it will internally rewrite the request (preserving what is in your browser's address bar) but the fragment (the #Skills) will be useless.
Fragments are used on the client side to tell it to handle the content that it requested in a certain way, usually, to page to where there is a named anchor. If the browser doesn't see the #Skills, it isn't going to page to the "Skills" named anchor. If you don't redirect, the browser won't see the fragment because it is being internally handled by the server and the server is going to ignore the fragment.
There may be some kind of javascript solution that tells the browser that the content it just loaded http://mypage/resume.php needs to be paged to a certain named anchor. It may be able to do it by looking at the browser's address bar, seeing that it is requesting /Skills, and onload() it pages to the Skills anchor.

Resources