Hello,
I'm using CFHTTPDownload Sample, i use CFHTTPMessageAppendBytes for HTTPRequest.
Why do it crasched my Appl. by ReadStremOpen() function.
Thank you for your advice,
My function
--------------------------------------------------------------------------------------------------------------------------------------
.
.
.
CFReadStreamRef readStreamRef = NULL;
CFStreamClientContext ctxt = { 0, (void*)NULL, NULL, NULL, NULL };
static EventLoopTimerUPP networkTimeoutTimerUPP;
UInt8 reqString[]="POST /cgi-bin/ConfigFile?0,0,0,0,0,0,0,0,0 HTTP/1.1\r\nHost: 192.168.1.100\r\nAccept-Language: en\r\nPragma: no-cache\r\nConnection: Keep-Alive\r\n
User-Agent: Mozilla/4.0 (compatible; MSIE 5.23; Mac_PowerPC)\r\nContent-type: multipart/form-data; boundary=---------------------------168071508944249\r\nExtension: Security/Remote-Passphrase\r\nAuthorization: Basic YWRtaW46YWRtaW4=\r\nContent-length: 33992\r\n\r\n";
// HTTP - Post Request Body
CFDataRef bodyData = NULL;
Boolean bAppendRes = false;
CFHTTPMessageRef messageRefRequest= CFHTTPMessageCreateEmpty(kCFAllocatorDefault,true);
CFHTTPMessageAppendBytes(messageRefRequest, reqString, strlen((const char*)reqString));
if(CFHTTPMessageIsHeaderComplete(messageRefRequest))
DebugMsgBox("\pDEBUG","\pHEADER IS COMPLETE");
else
DebugMsgBox("\pDEBUG","\pHEADER IS NOT COMPLOETE");
GetBody(&bodyData);
CFHTTPMessageAppendBytes(messageRefRequest, CFDataGetBytePtr(bodyData), CFDataGetLength(bodyData));
// Create the stream for the request.
readStreamRef = CFReadStreamCreateForHTTPRequest( kCFAllocatorDefault, messageRefRequest );
if ( readStreamRef == NULL )
{
goto Bail;
}
CFReadStreamSetProperty(readStreamRef, kCFStreamPropertyHTTPAttemptPersistentConnection, kCFBooleanTrue);
// Set the client notifier
if ( CFReadStreamSetClient( readStreamRef, kNetworkEvents, ReadStreamClientCallBack, &ctxt ) == false )
goto Bail;
// Schedule the stream
CFReadStreamScheduleWithRunLoop( readStreamRef, CFRunLoopGetCurrent(), kCFRunLoopCommonModes );
// Start the HTTP connection
if ( CFReadStreamOpen( readStreamRef ) == false ) //// <- Crashed HERE , WHY ??????
goto Bail;
// Set up a watch dog timer to terminate the download after 5 seconds
if ( networkTimeoutTimerUPP == NULL )
networkTimeoutTimerUPP = NewEventLoopTimerUPP( NetworkTimeoutTimerProc );
if ( gNetworkTimeoutTimerRef != NULL )
RemoveEventLoopTimer( gNetworkTimeoutTimerRef );
InstallEventLoopTimer( GetCurrentEventLoop(), kEventDurationSecond *10, 0, networkTimeoutTimerUPP, (void*)readStreamRef, &gNetworkTimeoutTimerRef );
Bail:
if ( bodyData != NULL) CFRelease( bodyData );
if ( messageRefRequest != NULL ) CFRelease( messageRefRequest );
if ( readStreamRef != NULL )
{
CFReadStreamSetClient( readStreamRef, NULL, NULL, NULL );
CFRelease( readStreamRef );
}
.
.
.
--------------------------------------------------------------------------------------------------------------------------------------