Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFReadStreamRead doesn't read data over SSL (HTTPS) server



 
 
Hi,

I'm writing a XML parser where i'm trying to get the URL with Authentication from HTTPS server. I'm using CFReadStreamRead to read the data over the HTTPS stream.

But "CFReadStreamRead" fails to read any data and throws up an error which when logged gives "-9812" which means "errUnknownRootCert" as seen in the "SecureTransport.h" header file.

Here is the code:

/********************************************************/

UInt8    buffer[kBufferSize];    //    Create the buffer
    CFIndex    bytesInBuffer = 0;
    CFHTTPMessageRef    messageRef = NULL;
    CFReadStreamRef          readStreamRef = NULL;
    Boolean bHTTPreturn = false;
    Boolean bFlag = false;

    CFMutableDataRef data = "" 0);

    if ( urlRef == NULL ) return;
   
    // Create the HTTP message
    messageRef = CFHTTPMessageCreateRequest( kCFAllocatorDefault, CFSTR("GET"), urlRef, kCFHTTPVersion1_1 );
    if ( messageRef == NULL ) return;

    // Create the stream for the request.
    readStreamRef    = CFReadStreamCreateForHTTPRequest( kCFAllocatorDefault, messageRef );
    if ( readStreamRef == NULL ) return;
   
    // Authentication
    if (username || password)
          bHTTPreturn = CFHTTPMessageAddAuthentication(messageRef, NULL, username, password, kCFHTTPAuthenticationSchemeBasic, false);
 
    // Enable auto-redirect
    if ( CFReadStreamSetProperty(readStreamRef, kCFStreamPropertyHTTPShouldAutoredirect, kCFBooleanTrue) == false )
          return;
   
    // Start the HTTP connection
    if ( CFReadStreamOpen( readStreamRef ) == false )
        return;

    // Set the timer
    UInt32 startTime = TickCount();
   
    // Loop, reading the data
    while (true) {
          UInt32 time = TickCount();
          if (time < startTime)
              startTime = 0;
          if ( time > startTime + kTimeout)
              return;

    CFStreamStatus rStatus = CFReadStreamGetStatus(readStreamRef);
          if (rStatus == kCFStreamStatusOpening)
              continue;
          if ((rStatus == kCFStreamStatusError) || (rStatus == kCFStreamStatusClosed) || (rStatus == kCFStreamStatusAtEnd))
              break;
   
          if (CFReadStreamHasBytesAvailable (readStreamRef)) {
   
              CFIndex bytesRead = CFReadStreamRead(readStreamRef, buffer, kBufferSize);
              fprintf(stdout, "\n bytesRead = %d\n", (int)bytesRead);
              if (bytesRead < 0) {
              CFStreamError cfErr;// = (CFStreamError) malloc (sizeof(CFStreamError));
              cfErr = CFReadStreamGetError(readStreamRef);
             
              fprintf(stdout, "\n inside  if (bytesRead < 0) cfErr.Error = %ld  \n domain = %d \n",cfErr.error, cfErr.domain);
//                    CFStreamError error = CFReadStreamGetError(readStreamRef);
                    return;
              } else {
                                        CFDataAppendBytes(data, buffer, bytesRead);
                    startTime = TickCount(); // Reset timer
              }
          }
    }   

/********************************************************/

Has anybody come across this problem?

Is there a way to overcome this? I want to know how to read data communicating with HTTPS servers or servers which are on SSL (Secure Socket Layer).

Thanks & Regards.
Yuvaraj




click jobs
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.