Created
April 5, 2012 18:11
-
-
Save aaronksaunders/2312930 to your computer and use it in GitHub Desktop.
Changes to get NTLM Working With Appcelerator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var xhr = Titanium.Network.createHTTPClient(); | |
// Set the property on http client, BEFORE OPEN | |
xhr.username = "ausername"; | |
xhr.password = "apassword@1234"; | |
xhr.domain = "adomain"; | |
xhr.setRequestHeader('Content-Type', "application/json; charset=utf-8"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void)open:(id)args | |
{ | |
RELEASE_TO_NIL(request); | |
NSString *method = [TiUtils stringValue:[args objectAtIndex:0]]; | |
[url release]; | |
url = [[TiUtils toURL:[args objectAtIndex:1] proxy:self] retain]; | |
if ([args count]>2) | |
{ | |
async = [TiUtils boolValue:[args objectAtIndex:2]]; | |
} | |
else | |
{ | |
async = YES; | |
} | |
request = [[ASIFormDataRequest requestWithURL:url] retain]; | |
[request setDownloadCache:[ASIDownloadCache sharedCache]]; | |
[request setDelegate:self]; | |
if (timeout) { | |
NSTimeInterval timeoutVal = [timeout doubleValue] / 1000; | |
[request setTimeOutSeconds:timeoutVal]; | |
} | |
if (hasOnsendstream) | |
{ | |
[request setUploadProgressDelegate:self]; | |
} | |
if (hasOndatastream) | |
{ | |
[request setDownloadProgressDelegate:self]; | |
} | |
[request addRequestHeader:@"User-Agent" value:[[TiApp app] userAgent]]; | |
// twitter specifically disallows X-Requested-With so we only add this normal | |
// XHR header if not going to twitter. however, other services generally expect | |
// this header to indicate an XHR request (such as RoR) | |
if ([[url host] rangeOfString:@"twitter.com"].location==NSNotFound) | |
{ | |
[request addRequestHeader:@"X-Requested-With" value:@"XMLHttpRequest"]; | |
} | |
[request setRequestMethod:method]; | |
[request setDefaultResponseEncoding:NSUTF8StringEncoding]; | |
// don't cache credentials, session etc since each request might be to | |
// different URI and cause security compromises if we do | |
[request setUseSessionPersistence:NO]; | |
[request setUseKeychainPersistence:NO]; | |
[request setUseCookiePersistence:YES]; | |
[request setShowAccurateProgress:YES]; | |
[request setShouldUseRFC2616RedirectBehaviour:YES]; | |
BOOL keepAlive = [TiUtils boolValue:[self valueForKey:@"enableKeepAlive"] def:YES]; | |
[request setShouldAttemptPersistentConnection:keepAlive]; | |
// NEW CODE ---- | |
[request setUsername:[TiUtils stringValue:[self valueForKey:@"username"]]]; | |
[request setPassword:[TiUtils stringValue:[self valueForKey:@"password"]]]; | |
[request setDomain:[TiUtils stringValue:[self valueForKey:@"domain"]]]; | |
// END NEW CODE -- | |
//handled in send, as now optional | |
//[request setShouldRedirect:YES]; | |
[self _fireReadyStateChange:NetworkClientStateOpened failed:NO]; | |
[self _fireReadyStateChange:NetworkClientStateHeaders failed:NO]; | |
} |
This is great, how can it be done for Android?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I have tried to implement this. I added the three new lines into TiNetworkHTTPClientProxy.m and added the .username, .password and .domain to my xhr, but still my responseText is the html for the login form that gets pushed to a browser.
I am really sorry if I have just missed something obvious, but I am desperate to make this work. Any advice or pointers would be greatly appreciated.
Thanks mate
Paul