• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
CFHTTPRequest issue
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFHTTPRequest issue


  • Subject: CFHTTPRequest issue
  • From: Arjun SM <email@hidden>
  • Date: Mon, 29 Apr 2013 12:14:38 +0530

Hi all ,

I am trying to read a response from a HTTP request. The issue is that I am getting different results when run the binary on Snow-Leopard, Lion and Mountain Lion OS X. The below code works fine on Snow Leopard but not on Lion and ML OS.

Below is the code

#include <CoreFoundation/CoreFoundation.h>
#include <CoreServices/CoreServices.h>


#define YOUTUBE_API_SERVER       "gdata.youtube.com"
#define YOUTUBE_API_VIDEO_FEED   "/feeds/api/videos/"


int main(int argc, char *argv[])
{
    CFStringRef youtubeURLStr;
    youtubeURLStr = CFStringCreateWithFormat(NULL, NULL, CFSTR("http://%s%s%s"), YOUTUBE_API_SERVER, YOUTUBE_API_VIDEO_FEED,"zMa9CT29cQE?fs=1");
    CFShow(youtubeURLStr);
    CFURLRef cfUrl = CFURLCreateWithString(kCFAllocatorDefault, youtubeURLStr, NULL);
    CFHTTPMessageRef cfHttpReq = CFHTTPMessageCreateRequest(kCFAllocatorDefault, CFSTR("GET"), cfUrl, kCFHTTPVersion1_1);
   
    CFReadStreamRef readStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, cfHttpReq);
    CFReadStreamOpen(readStream);
   
    CFHTTPMessageRef cfHttpResp = CFHTTPMessageCreateEmpty(kCFAllocatorDefault, TRUE);
   
    CFIndex numBytesRead;
    do
    {
        const int nBuffSize = 1024;
        UInt8 buff[nBuffSize];
        numBytesRead = CFReadStreamRead(readStream, buff, nBuffSize);
       
        if( numBytesRead > 0 )
        {
            CFHTTPMessageAppendBytes(cfHttpResp, buff, numBytesRead);
        }
        else
        if( numBytesRead < 0 )
        {
            CFStreamError error = CFReadStreamGetError(readStream);   
        }
       
    } while( numBytesRead > 0 );
   
   
    CFDataRef cfResp = CFHTTPMessageCopyBody(cfHttpResp);
    CFHTTPMessageRef myResponse = (CFHTTPMessageRef)CFReadStreamCopyProperty(readStream, kCFStreamPropertyHTTPResponseHeader);
    CFShow(myResponse);
    CFShow(cfResp);
 

    CFReadStreamClose(readStream);
    CFRelease(cfUrl);
    CFRelease(cfHttpReq);
    CFRelease(readStream);
    CFRelease(cfHttpResp);
   
    return 0;
}


Results On Snow-Leoaprd ,
<CFHTTPMessage 0x100109f60>{url = "" href="http://gdata.youtube.com/feeds/api/videos/zMa9CT29cQE?fs=1">http://gdata.youtube.com/feeds/api/videos/zMa9CT29cQE?fs=1; status = HTTP/1.1 200 OK}
<CFData 0x10083b200 [0x7fff7008cee0]>{length = 3711, capacity = 3711, bytes = 0x3c3f786d6c2076657273696f6e3d2731 ... 3c2f656e7472793e}

Result on Lion and Mountain Lion,
http://gdata.youtube.com/feeds/api/videos/zMa9CT29cQE?fs=1
<CFHTTPMessageRef 0x7fbc5490b1f0(0x7fbc5490b200)> { parsed response, url = "" href="http://gdata.youtube.com/feeds/api/videos/zMa9CT29cQE?fs=1">http://gdata.youtube.com/feeds/api/videos/zMa9CT29cQE?fs=1, status = 200 }
<CFData 0x7fbc52e022c0 [0x7fff7371afa0]>{length = 0, capacity = 0, bytes = 0x}


Can anyone point out the problem with the code i have written above?


thanks for all the help
~Arjun


 _______________________________________________
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

  • Follow-Ups:
    • Re: CFHTTPRequest issue
      • From: "Quinn \"The Eskimo!\"" <email@hidden>
  • Prev by Date: Re: network-authentication UIBackgroundMode on iOS
  • Next by Date: Re: Our question is how to display in iOS WLAN SSID a subtile that to mark this SSID is our support Wi-If hotspots.
  • Previous by thread: Re: network-authentication UIBackgroundMode on iOS
  • Next by thread: Re: CFHTTPRequest issue
  • Index(es):
    • Date
    • Thread