Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6716317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:43:07+00:00 2026-05-26T08:43:07+00:00

I wanted to try the example code given in the CFNetwork programming guide under

  • 0

I wanted to try the example code given in the CFNetwork programming guide under sub-section ‘Communicating with HTTP servers’. I tried the same example code, but the problem is it just opens the stream it does not send the http request. The exact code which I wrote in my application is as below. According to the documentation when I call the CFReadStreamOpen function it serializes and sends the http request. But when I see the packets in the wireshark. I can see just three TCP packets which are actually packlets of TCP connection three way handshake. So what’s the problem????

CFStringRef bodyData = CFSTR("mydata is here"); // Usually used for POST data

CFStringRef headerFieldName = CFSTR("X-My-Favorite-Field");
CFStringRef headerFieldValue = CFSTR("Dreams");

CFStringRef url = CFSTR("http://www.darshan.com");
CFURLRef myURL = CFURLCreateWithString(kCFAllocatorDefault, url, NULL);

CFStringRef requestMethod = CFSTR("POST");
CFHTTPMessageRef myRequest =
    CFHTTPMessageCreateRequest(kCFAllocatorDefault, requestMethod, myURL,
                               kCFHTTPVersion1_1);

CFHTTPMessageSetBody(myRequest, bodyData);
CFHTTPMessageSetHeaderFieldValue(myRequest, headerFieldName, headerFieldValue);
CFReadStreamRef myReadStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, myRequest);

CFReadStreamOpen(myReadStream);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:43:08+00:00Added an answer on May 26, 2026 at 8:43 am

    here is the solution , when you create the CFHTTPMessage you should serialize it (for example in my code I used UTF8 ) and then write to to server .

    here is my code sample you can follow this example it is working great :

    CFHTTPMessageRef myRequest = CFHTTPMessageCreateRequest(kCFAllocatorDefault,CFSTR("POST"), myURL, kCFHTTPVersion1_1);  
        CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("Content-Type"), CFSTR("application/x-www-form-urlencoded"));
        CFHTTPMessageSetHeaderFieldValue(myRequest, CFSTR("Content-Length"), (CFStringRef)postLength);
        CFHTTPMessageSetBody(myRequest, (CFDataRef)postData); // postData is NSData 
    dataReadStream = CFReadStreamCreateForHTTPRequest(kCFAllocatorDefault, myRequest);
    

    //// From here Is Connection To Server

    CFStreamCreatePairWithSocketToHost(kCFAllocatorDefault, 
                                           (CFStringRef) serverHost, 
                                           serverPort, 
                                           &dataReadStream, 
                                           &dataWriteStream);
    
    if (dataReadStream && dataWriteStream) {
        CFReadStreamSetProperty(dataReadStream, 
                                kCFStreamPropertyShouldCloseNativeSocket, 
                                kCFBooleanTrue);
        CFWriteStreamSetProperty(dataWriteStream, 
                                 kCFStreamPropertyShouldCloseNativeSocket, 
                                 kCFBooleanTrue);
    
        iStream = (NSInputStream *)dataReadStream;
        [iStream retain];
        [iStream setDelegate:self];
        [iStream scheduleInRunLoop:[NSRunLoop currentRunLoop] 
                           forMode:NSDefaultRunLoopMode];
        [iStream open];
    
        oStream = (NSOutputStream *)dataWriteStream;
        [oStream retain];
        [oStream setDelegate:self];
        [oStream scheduleInRunLoop:[NSRunLoop currentRunLoop] 
                           forMode:NSDefaultRunLoopMode];
        [oStream open];
    

    ///Now Write Your Command To Server

    NSString *content = [NSString stringWithFormat:@"Your Command"];
    NSString *req = [NSString stringWithFormat:@"POST /client HTTP/1.1\r\nContent-Length: %d\r\n\r\n%@\r\n", [content length], content];
    
    [oStream write:(const UInt8 *)[req UTF8String] maxLength:strlen((char*)[req UTF8String])];
    

    then receive the notification in just dont Forget to add to header file

    -(void)stream:(NSStream *)aStream handleEvent:(NSStreamEvent)eventCode
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When reading a PHP book I wanted to try my own (continue) example. I
I wanted to try a little design by contract in my latest C# application
I have wanted to try GAE since launch, but coming from ASP .NET and
so I wanted to try my first CLR project in Visual C++. So I
After I've seen this PDC session I wanted to try to learn a bit
Inspired by this question , I wanted to try my hand at the latest
I am working on some scraping app, i wanted to try to get it
I have a quick little application and wanted to give a try to develop
I wanted to make some simple file recovery software, where I want to try
I just wanted to try out some shaders on a flat image. Turns out

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.