CocoaHTTPServer help
CocoaHTTPServer help
- Subject: CocoaHTTPServer help
- From: alex gordillo <email@hidden>
- Date: Wed, 11 Jan 2006 14:15:28 -0500
Greetings All,
I'm having trouble getting Safari to return XML data generated from
requests I'm sending an HTTP server that I create using the
CocoaHTTPServer sample code. Under the - (void)
performDefaultRequestHandling:(HTTPServerRequest *)mess method,
I modified the 404 handler to process the requests since I have no
implicit file system. Every time I send a request it seems to throw
an exception when it attempts to create the body of the message:
if ([method isEqual:@"GET"]) {
NSURL *uri = [(NSURL *)CFHTTPMessageCopyRequestURL(request)
autorelease];
NSURL *url = [NSURL URLWithString:[uri path] relativeToURL:
[server documentRoot]];
NSString *uriString = [[(NSURL *)CFHTTPMessageCopyRequestURL
(request) autorelease] relativeString];
NSData *data = [NSData dataWithContentsOfURL:url];
if (![uriString isEqualToString:@"/favicon.ico"])
{
if (!data) {
NSString *weRock;
NSData *weRockasData;
NSArray *uriArray = [uriString componentsSeparatedByString:@"/"];
weRock = [server routeRequest:uriArray];
weRock = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=
\"utf-8\" ?>%@", weRock];
weRockasData = [NSKeyedArchiver archivedDataWithRootObject:weRock];
NSData *weRockasDataFinal = [NSKeyedUnarchiver
unarchiveObjectWithData:weRockasData];
CFHTTPMessageRef response = CFHTTPMessageCreateResponse
(kCFAllocatorDefault, 200, NULL, kCFHTTPVersion1_1);
CFHTTPMessageSetHeaderFieldValue(response, (CFStringRef)@"Content-
Length", (CFStringRef)[NSString stringWithFormat:@"%d",
[weRockasDataFinal length]]);
CFHTTPMessageSetBody(response, (CFDataRef)weRockasDataFinal); //
<---- this is the statement that throws the exception
[mess setResponse:response];
CFRelease(response);
return;
}
}
Am I wrong in trying to encode the XML string weRock into an NSData
object and then unarchiving it to remove the text artifacts so I can
then pass it to CFHTTPMessageSetBody?
Am I missing something? Any help would be appreciated.
Thanks,
Alex
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden