• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
EXC_BAD_ACCESS when trying to use [NSMutableURLRequest setHTTPBodyStream]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EXC_BAD_ACCESS when trying to use [NSMutableURLRequest setHTTPBodyStream]


  • Subject: EXC_BAD_ACCESS when trying to use [NSMutableURLRequest setHTTPBodyStream]
  • From: Dave Carrigan <email@hidden>
  • Date: Wed, 9 Jan 2008 16:03:00 -0800

I'm writing a test command-line tool that only uses Foundation. I want to send a file to a server using HTTP PUT. The minimal code needed to reproduce the problem is included at the bottom of this message.

When I run the program, I get an EXC_BAD_ACCESS with the following stack trace

#0 0x9681177b in CFWriteStreamClose ()
#1 0x9636a8dc in spoolingClose ()
#2 0x9681157d in _CFStreamClose ()
#3 0x968da22f in closeRequestResources ()
#4 0x968d58c3 in httpConnectionStateChanged ()
#5 0x968f0f94 in sendStateChanged ()
#6 0x968f0f1e in _CFNetConnectionErrorOccurred ()
#7 0x968e220c in httpRequestPayloadCallBack ()
#8 0x9680f629 in _CFStreamSignalEventSynch ()
#9 0x967fd64e in CFRunLoopRunSpecific ()
#10 0x967fdd38 in CFRunLoopRunInMode ()
#11 0x96203560 in +[NSURLConnection(NSURLConnectionReallyInternal) _resourceLoadLoop:] ()
#12 0x961a004d in -[NSThread main] ()
#13 0x9619fbf4 in __NSThread__main__ ()
#14 0x947de075 in _pthread_start ()
#15 0x947ddf32 in thread_start ()


The fault happens before my delegate receives a single message from the NSURLConnection. Any suggestions as to what I'm doing wrong?

--
Dave Carrigan
email@hidden
Seattle, WA, USA

#import <Foundation/Foundation.h>

@interface Uploader : NSObject
{
}
- (id)initWithURL:(NSURL*)url withUploadFile:(NSString*)filename;
- (void)connection:(NSURLConnection*)connection didReceiveResponse: (NSURLResponse*)theResponse;
- (void)connection:(NSURLConnection*)connection didReceiveData: (NSData*)data;
- (void)connection:(NSURLConnection*)connection didFailWithError: (NSError*)error;
- (void)connectionDidFinishLoading:(NSURLConnection*)connection;
@end


@implementation Uploader
- (id)initWithURL:(NSURL*)url withUploadFile:(NSString*)filename
{
NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:60.0];
[request setHTTPBodyStream:[NSInputStream inputStreamWithFileAtPath:filename]];
[request setHTTPMethod:@"PUT"];
[NSURLConnection connectionWithRequest:request delegate:self];
return self;
}


- (void)connection:(NSURLConnection*)connection didReceiveResponse: (NSURLResponse*)theResponse
{
}


- (void)connection:(NSURLConnection*)connection didReceiveData: (NSData*)data
{
write(1, [data bytes], [data length]);
}


- (void)connection:(NSURLConnection*)connection didFailWithError: (NSError*)error
{
fprintf(stderr, "Failed\n");
exit(1);
}


- (void)connectionDidFinishLoading:(NSURLConnection*)connection
{
  fprintf(stderr, "All done\n");
  exit(0);
}

@end

int main (int argc, const char * argv[]) {
  [[NSAutoreleasePool alloc] init];

  NSURL* url = [NSURL URLWithString:@"http://localhost:23456/reflect";];
  [[Uploader alloc] initWithURL:url withUploadFile:@"/etc/hosts"];
  [[NSRunLoop currentRunLoop] run];
  // Will never get here
  return 0;
}

Attachment: PGP.sig
Description: This is a digitally signed message part

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:

This email sent to email@hidden

  • Prev by Date: Re: Daemon application with System Preferences Pane
  • Next by Date: NSMenuItem / NSMenu Problems
  • Previous by thread: Re: Daemon application with System Preferences Pane
  • Next by thread: Re: EXC_BAD_ACCESS when trying to use [NSMutableURLRequest setHTTPBodyStream]
  • Index(es):
    • Date
    • Thread