Re: NSURLRequest and HTTP PUT?
Re: NSURLRequest and HTTP PUT?
- Subject: Re: NSURLRequest and HTTP PUT?
- From: Jan van Doorn <email@hidden>
- Date: Tue, 25 May 2004 08:44:23 -0700
Any suggestions as to what the best "something other than
NSMutableURLRequest/NSURLConnection" would be?
Are there more known bugs like this? I am working on a WebDAV client,
I'll need a bunch more very infrequently used methods....
Thanks,
JvD
On May 24, 2004, at 9:11 PM, Jonathan Younger wrote:
It's a known bug. The only option at this point is to use something
other than NSMutableURLRequest/NSURLConnection to do the HTTP PUT.
-Jonathan
On May 24, 2004, at 8:24 PM, Jan van Doorn wrote:
Hello,
Sorry if this is easy to be found in docs or on the web, but I tried,
and couldn't find anything remotely helpful. I am still pretty new to
Cocoa, and even newer to this list, so again, please excuse me if I
am asking the wrong question, or the wrong people.
I am trying to do a HTTP PUT from my Cocoa application. I used Neon
(http://www.webdav.org/neon) before, that worked, but I had some
stability problems, and want a bit more flexibility, so now, I am
looking into NSURL* (Request, Response, Connection) to do the job.
My problem is that it seems to never actually send the body with the
PUT request. Below is a little snippet of code. It sends the request,
but, there is no Content-Length: header, and the body is 0 bytes. If
I just change the "[request setHTTPMethod:@"PUT"];" to "[request
setHTTPMethod:@"POST"];" it actually will include the body in the
request, and gives me a Content-Length: header for free. But I want
to PUT, not POST. I used ethereal to verify the contents of the
request when it arrives at the server.
I am pretty sure the NSURLRequest should support the "PUT" method, it
does support the more exotic (webdav) MKCOL method, I got that
working in just a couple of minutes.... There's no body with that
though.
----- code snippet -----
NSString *sourceFileName = "/Users/JvD/tmp/testfile.txt";
NSString *urlString=[[NSString alloc]
initWithString:@"http://myserver.mydomain.com/testfile.txt"];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:urlString]];
NSData *fileData = [[NSData alloc]
initWithContentsOfFile:sourceFileName];
[request setHTTPMethod:@"PUT"];
[request setHTTPBody:[fileData retain]]; // I tried with and
without retain message
NSData *body = [request HTTPBody];
NSLog(@"data: %@", [[NSString alloc]initWithData:body
encoding:NSUTF8StringEncoding]); // this show the contents of the txt
file
NSData *respData;
NSURLResponse *response;
NSError *error;
respData = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
----- /code snippet -----
Any and all help would be appreciated.
Cheers,
JvD
_______________________________________________
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.
_______________________________________________
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.
--
Jan van Doorn
Liberate Technologies
email@hidden
720 244 9872
_______________________________________________
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.