NSMutableURLRequest setHTTPMethod:
NSMutableURLRequest setHTTPMethod:
- Subject: NSMutableURLRequest setHTTPMethod:
- From: Jonathan Younger <email@hidden>
- Date: Tue, 23 Mar 2004 21:19:02 -0800
I'm trying to issue an HTTP "PUT" request using the NSMutableURLRequest
setHTTPMethod: in conjunction with setHTTPBody: but the HTTPBody does
not appear to be sent with the request. NSMutableURLRequest sends the
HTTPBody when using "POST" but not "PUT".
Here is a minimal function duplicating this behavior:
- (void)putTest
{
NSError *error;
NSURLResponse *response;
NSData *dataReply;
NSString *stringReply;
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:
[NSURL URLWithString: @"
http://localhost/cgi-bin/put.cgi"]];
[request setHTTPMethod: @"PUT"]; // With the setHTTPMethod set to
"PUT" the HTTPBody is not being sent
//request setHTTPMethod: @"POST"]; // Changing the setHTTPMethod to
"POST" sends the HTTPBody
[request setHTTPBody: [[NSString stringWithString:@"test"]
dataUsingEncoding: NSUTF8StringEncoding]];
dataReply = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response error:&error];
stringReply = [[NSString alloc] initWith
Data:dataReply
encoding:NSUTF8StringEncoding];
NSLog(@"%@", stringReply); // Expected result is: @"test\n\n"
actual result is: @"\n\n"
[stringReply release];
}
Here is the put.cgi file that echoes back the data sent from the
request:
#!/usr/bin/perl
print "Content-type: text/plain\n\n";
$dataLength = $ENV{'CONTENT_LENGTH'};
$bytesRead = read(STDIN, $data, $dataLength);
print $data;
print "\n\n";
It looks like a bug with NSMutableURLRequest to me, but maybe I'm wrong.
-Jonathan
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.