CFNetwork can not get data through proxy
CFNetwork can not get data through proxy
- Subject: CFNetwork can not get data through proxy
- From: ben peng <email@hidden>
- Date: Thu, 24 Apr 2003 18:21:20 +0800
Hi all,
I want do a "get" through a proxy with authentication, and I get a
407 error. but the username and password seem useless. I repeat receive
the kCFStreamEventOpenCompleted and kCFStreamEventErrorOccurred. who
can help me? thank you.
the following is my code of get:
do get
messageRef = CFHTTPMessageCreateRequest( kCFAllocatorDefault,
CFSTR("GET"), m_UrlReference, kCFHTTPVersion1_1 );
mResponseRef = CFHTTPMessageCreateResponse( kCFAllocatorDefault, 407,
NULL, kCFHTTPVersion1_1);
// Create the stream for the request.
readStreamRef = CFReadStreamCreateForHTTPRequest( kCFAllocatorDefault,
messageRef );
CFHTTPReadStreamSetRedirectsAutomatically( readStreamRef, true );
CFStringRef theProxy = CFSTR("192.168.1.86");
long thePort = 8080;
CFHTTPReadStreamSetProxy(readStreamRef, theProxy, thePort);
// Set the client notifier
if ( CFReadStreamSetClient( readStreamRef, kNetworkEvents,
g_pfnMachOCFNetworkCallback, &ctxt ) == false )
{
return;
}
// Schedule the stream
CFReadStreamScheduleWithRunLoop( readStreamRef, CFRunLoopGetCurrent(),
kCFRunLoopCommonModes );
// Start the HTTP connection
if ( CFReadStreamOpen( readStreamRef ) == false )
{
return;
}
if ( messageRef != NULL )
{
CFRelease( messageRef );
messageRef = nil;
}
the following is my code when I receive a kCFStreamEventErrorOccurred
in callback function
Set username and password
UInt32 theStatus = CFHTTPMessageGetResponseStatusCode(mResponseRef);
if (theStatus == 407)
{
CFReadStreamClose(readStreamRef);
CFRelease(readStreamRef);
readStreamRef = NULL;
if (messageRef)
{
CFRelease(messageRef);
messageRef = NULL;
}
if (mResponseRef)
{
CFRelease(mResponseRef);
mResponseRef = NULL;
}
messageRef = CFHTTPMessageCreateRequest( kCFAllocatorDefault,
CFSTR("GET"), m_UrlReference, kCFHTTPVersion1_1 );
mResponseRef = CFHTTPMessageCreateResponse( kCFAllocatorDefault, 407,
NULL, kCFHTTPVersion1_1);
readStreamRef = CFReadStreamCreateForHTTPRequest(
kCFAllocatorDefault, messageRef );
CFHTTPReadStreamSetRedirectsAutomatically( readStreamRef, true );
CFStringRef theUsername = CFSTR("guest");
CFStringRef thePass = CFSTR("pass");
CFHTTPMessageAddAuthentication(messageRef, mResponseRef, theUsername,
thePass, kCFHTTPAuthenticationSchemeBasic, TRUE);
CFStringRef theProxy = CFSTR("192.168.1.86");
long thePort = 8080;
CFHTTPReadStreamSetProxy(readStreamRef, theProxy, thePort);
if ( CFReadStreamSetClient( readStreamRef, kNetworkEvents,
g_pfnMachOCFNetworkCallback, &ctxt ) == false )
{
return;
}
CFReadStreamScheduleWithRunLoop( readStreamRef,
CFM_CFRunLoopGetCurrent(), nil );
if ( CFReadStreamOpen( readStreamRef ) == false )
{
return;
}
}
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.