Re: accessing the CFSteam that NSURLConnection is using?
Re: accessing the CFSteam that NSURLConnection is using?
- Subject: Re: accessing the CFSteam that NSURLConnection is using?
- From: sean <email@hidden>
- Date: Wed, 12 Oct 2005 14:04:20 -0700
Excellent, this is a great jump start from where I was stuck, thank you.
I converted my NSURLRequest to use a NSInputStream instead of just an
NSData, which seems to be working great. Sample code below:
// [snip]
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString
stringWithFormat:@"--%@\r\n",stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString
stringWithFormat:@"Content-Disposition: form-data; name=\"upload\";
filename=\"%@\"\r\n", [imagePath lastPathComponent]]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithString:@"Content-Type:
application/octet-stream\r\n\r\n"]
dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[NSData dataWithContentsOfFile:imagePath]];
[postBody appendData:[[NSString
stringWithFormat:@"\r\n--%@--\r\n",stringBoundary]
dataUsingEncoding:NSUTF8StringEncoding]];
// [postRequest setHTTPBody:postBody];
[postRequest setHTTPBodyStream:[NSInputStream
inputStreamWithData:postBody]];
// [snip]
I have the logic twisted around in my head at the moment, and I'm not
sure how to determine how much data has been written to the server via
the POST request from NSInputStream (conceptually, it seems like this
should be an NSOutputStream, doesn't it?)
Meanwhile, back at Bat headquarters (after the POST connection is
connected), this isn't working:
NSInputStream *requestInputStream = [eachUrlRequest HTTPBodyStream];
unsigned int * numBytes;
uint8_t * buffer;
if ( [requestInputStream getBuffer:&buffer length: numBytes] ) {
NSLog(@"Sweet, we got the numBytes! length: %d", numBytes);
} else {
NSLog(@"Nimrod!, you did it wrong again!");
}
On 10/12/05, Simon Spero <email@hidden> wrote:
> On Oct 12, 2005, at 3:28 AM, sean wrote:
>
> > I was looking around in the CFNetworking documentation and it looks
> > like if I can get access to the CFStream that the NSURLConnection
> > us using, I could query it for the current upload info via
> > kCFStreamPropertyHTTPRequestBytesWrittenCount.
>
> Forgot to add: you get the NSInputStream itself by from -
> [NSURLRequest HTTPBodyStream]
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden