Question about CFHTTPMessageAppendBytes
Question about CFHTTPMessageAppendBytes
- Subject: Question about CFHTTPMessageAppendBytes
- From: "Alex Guo" <email@hidden>
- Date: Wed, 8 Dec 2004 09:58:56 +0800
Hi, All,
The prototype of function CFHTTPMessageAppendBytes is as the below:
Boolean CFHTTPMessageAppendBytes (
CFHTTPMessageRef message,
const UInt8 *newBytes,
CFIndex numBytes);
According to the official description, this function is used to append the
data specified by newBytes to the specified message object which was created
by calling CFHTTPMessageCreateEmpty.
My question is that when I send out a request, does it make sense that I use
this function to append HttpHeader to the request directly instead of using
CFHTTPMessageSetHeaderFieldValue ?
And, I've read the GetExample source code provided with XCode, which gets
response by using function CFReadStreamCopyProperty as the following shows(I
don't mean this is a miss, because this code chunk is just used to get http
header.):
_response = (CFHTTPMessageRef)CFReadStreamCopyProperty(_stream,
kCFStreamPropertyHTTPResponseHeader);
I think, CFReadStreamCopyProperty just gets specified property, and can't
get all response message. And We should use
CFHTTPMessageAppendBytes to do that like below:
void handleBytesAvailable() {
UInt8 buffer[2048];
CFIndex bytesRead = CFReadStreamRead(_stream, buffer, sizeof(buffer));
// Less than zero is an error
if(bytesRead < 0) {
handleStreamError();
}
else if(bytesRead != 0) {
if(_response == NULL) {
_response = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, FALSE);
}
if(! CFHTTPMessageAppendBytes(_response, buffer, bytesRead)) {
printf("error: append bytes to response\n");
return;
}
}
}
Am I right? Thanks for any tip.
Alex
_______________________________________________
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