• 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
CFReadStreamCreateForHTTPRequest
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CFReadStreamCreateForHTTPRequest


  • Subject: CFReadStreamCreateForHTTPRequest
  • From: Chris Branch <email@hidden>
  • Date: Thu, 30 Mar 2006 11:23:18 -0500

I'm trying to create a simple C++ class that is able to send an HTTP
request and retrieve the response on OS X (10.2 and later).  For
example, suppose the interface for my class looks like this:

class cInternetRequest {
public:
	cInternetRequest();
	virtual ~cInternetRequest();

	bool Open(const char *url);
	bool Read(char *buffer, int bytesToRead, int *bytesRead) const;
	void Close();

	bool GetHttpStatusCode(int *statusCode) const;

	... more stuff omitted ...
};

Sample usage of this class might look like:

	if (request.Open("www.somedomain.com/example.php")) {
		if (request.GetHttpStatusCode(&httpStatus) && httpStatus == 200) {
			do {
				success = request.Read(buffer, sizeof(buffer), &numBytes);
				// ...process response...
			} while (success && numBytes > 0);
		}

		request.Close();
	}


It looks like the implementation of this should be pretty
straightforward using CFHTTPMessageCreateRequest() and
CFReadStreamCreateForHTTPRequest(), but there are a few aspects that
Apple's documentation does not seem to cover.

In my Open() method, I would call CFHTTPMessageCreateRequest() to create
the request, then call CFReadStreamCreateForHTTPRequest() and
CFStreamOpen() to actually send the request.  Questions:

1) Does CFReadStreamCreateForHTTPRequest() take a "snapshot" of the
CFHTTPMessageRef parameter?  In other words, is it safe to CFRelease the
CFHTTPMessageRef immediately after calling
CFReadStreamCreateForHTTPRequest, or does the CFHTTPMessageRef have to
persist until the stream is closed/released?

2) Does CFReadStreamOpen() block until HTTP response headers are
available?  If no, how do I know when it's "safe" to call
CFReadStreamCopyProperty() to get the response headers?  If
CFReadStreamOpen() DOES block, what happens if there's a network error?
Will it timeout?  How long?

Thanks!
Chris
 _______________________________________________
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: CFReadStreamCreateForHTTPRequest
      • From: "Duane Murphy" <email@hidden>
  • Prev by Date: Re: kCFStreamPropertyHTTPAttemptPersistentConnection
  • Next by Date: Re: CFReadStreamCreateForHTTPRequest
  • Previous by thread: Re: Deleting/adding ARP entries
  • Next by thread: Re: CFReadStreamCreateForHTTPRequest
  • Index(es):
    • Date
    • Thread