I'm doing an async NSURLConnection and am having issues. It's an http connection, and at first it seems to work. The server sends an authentication challenge (as it should), I respond with credentials, the servers seems to accept the credentials. Then the server responds with an HTTP header like this:

2008-09-26 17:43:20.681 TestApp[27403:10b] 200 - no error
2008-09-26 17:43:20.682 TestApp[27403:10b] {
    Date = "26 Sep 2008 17:43:20 -0800";
    "Max-Age" = 0;
}

There's no content length, and I never get data from the server. Other programs interact with this same server just fine, so I don't think it's the server end. Also, if I set a breakpoint on the line where I set the credentials, pause the program there, and then resume it, it works just fine.

Code is pasted below...

-(void)awakeFromNib
{
NSString *requestText = [NSString stringWithContentsOfFile:@"/ Untitled.txt"];
    NSDictionary *headerFieldsDict = [NSDictionary
                                                                          
dictionaryWithObjectsAndKeys:@"SomeClient",@"User-Agent",
@"text/xml; charset=utf-8", @"Content-Type",
                                      @"aSoapAction",@"SOAPAction",
                                      @"aHost",@"Host",
[NSString stringWithFormat:@"%d", [[requestText dataUsingEncoding:NSUTF8StringEncoding] length]],@"Content-Length", nil]; NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://staging.common.virtualearth.net/find-30/common.asmx "]]; [request setHTTPBody:[requestText dataUsingEncoding:NSUTF8StringEncoding]];
        [request setAllHTTPHeaderFields:headerFieldsDict];
        [request setHTTPMethod:@"POST"];
        [request setCachePolicy:NSURLRequestReloadIgnoringLocalCacheData];
        NSLog([[request allHTTPHeaderFields] description]);
        NSLog([NSString stringWithUTF8String:[[request HTTPBody] bytes]]);
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
        [connection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
        //pause here using gdb and the program works
        NSLog(@"Wanted authentication...");
NSURLCredential *credential = [NSURLCredential credentialWithUser:@"user" password:@"pass" persistence:NSURLCredentialPersistenceForSession];
        NSLog([[challenge sender] description]);
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}

- (void)connection:(NSURLConnection *)connection didCancelAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge
{
        NSLog(@"authentication canceled..");
}

- (void)connection:(NSURLConnection *)connection didReceiveData: (NSData *)data
{
        NSLog(@"Got data...");
        NSLog([NSString stringWithUTF8String:(const char *)[data bytes]]);
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse: (NSHTTPURLResponse *)response
{
        NSLog(@"Got Response..");
        NSLog(@"Expected return length %i", [response expectedContentLength]);
NSLog(@"%d - %@", [response statusCode], [NSHTTPURLResponse localizedStringForStatusCode:[response statusCode]]);
        NSLog([[response allHeaderFields] description]);
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
        NSLog(@"Done");
}

- (void)connection:(NSURLConnection *)connection didFailWithError: (NSError *)error
{
        NSLog(@"Error");
}
_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to