• 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
NSMutableURLRequest setHTTPMethod:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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] initWithData: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.


  • Prev by Date: Re: Repost : Nested Modal Window in Cocoa framework.Is it a bug in Cocoa framework?Anyone from Apple listening?
  • Next by Date: Re: SQLite Database
  • Previous by thread: Re: Repost : Nested Modal Window in Cocoa framework.Is it a bug in Cocoa framework?Anyone from Apple listening?
  • Next by thread: NSKeyedArchiver -> NSDictionary?
  • Index(es):
    • Date
    • Thread