titanium-sdk icon indicating copy to clipboard operation
titanium-sdk copied to clipboard

feat(android): add ignoreXRequestedWith to HTTPClient

Open m1ga opened this issue 1 year ago • 0 comments

Adds ignoreXRequestedWith to the HTTPClient to remove the X-Requested-With:XMLHttpRequest header. It is set automatically except for Twitter. But other pages don't like that either since it is used to check for "Ajax calls" (https://stackoverflow.com/a/48302354/5193915)

Old info for Twitter: https://jira-archive.titaniumsdk.com/TIMOB/TIMOB-729 Requested in Slack; paySmart3D check for "ajax requests"

Test run and check for the returned output

var url = "https://httpbin.org/post";
var client = Ti.Network.createHTTPClient({
	ignoreXRequestedWith: true,
	onload: function(e) {
		Ti.API.info("Received text: " + this.responseText);
	}
});
client.open("POST", url);
client.send();

X-Requested-With": "XMLHttpRequest", shouldn't be visible after this PR

Note: Same should be done for iOS: https://github.com/tidev/titanium_mobile/blob/81d3f4a1bfa69a5367b8cf05af40b608b62ebe3b/iphone/Classes/TiNetworkHTTPClientProxy.m#L90-L92

Feedback from slack: Removing that line made the API call successful.

m1ga avatar Aug 30 '22 13:08 m1ga