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);
here is the solution , when you create the
CFHTTPMessageyou 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 :
//// From here Is Connection To Server
///Now Write Your Command To Server
then receive the notification in just dont Forget to add to header file