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]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is great, how can it be done for Android?