• 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
Re: CFNetwork, HTTP and POST messages
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: CFNetwork, HTTP and POST messages


  • Subject: Re: CFNetwork, HTTP and POST messages
  • From: Becky Willrich <email@hidden>
  • Date: Thu, 15 Dec 2005 14:46:39 -0800

You need to configure the request BEFORE creating the stream - the two CFReadStreamCreate calls will take a copy of the request. That's probably why the body of the request is empty. Just move the CFHTTPMessageAddAuthentication(), CFHTTPMessageSetHeaderFieldValue(), and CFHTTPMessageSetBody() calls to prior to the CFReadStreamCreate() calls.

Hope that helps,
REW



On Dec 15, 2005, at 1:47 PM, David Lalonde wrote:

I just used the tcpflow utility as suggested by Jim Luther (great utility - thanks!) and it shows: no body data; a body length of zero.

Methinks I will be asked more details. Let me preempt you all on this:

I start by creating a message with
CFHTTPMessageCreateRequest (kCFAllocatorDefault, CFSTR ("POST"), requestCFURLRefVal, kCFHTTPVersion1_1)


I then create a read stream with either of
CFReadStreamCreateForHTTPRequest (kCFAllocatorDefault, requestCFHTTPMessageRefVal)
CFReadStreamCreateForStreamedHTTPRequest (kCFAllocatorDefault, requestCFHTTPMessageRefVal, streamStructPtr->bodyCFReadStreamRefVal)


Next comes the proxy settings with
CFReadStreamSetProperty (streamStructPtr->requestCFReadStreamRefVal, kCFStreamPropertyHTTPProxy, CFDictionaryRefVal)
CFHTTPMessageAddAuthentication (requestCFHTTPMessageRefVal, NULL, proxyUsernameCFStringRefVal, proxyPasswordCFStringRefVal, kCFHTTPAuthenticationSchemeBasic, TRUE)


I add the Content-Length field header with
CFHTTPMessageSetHeaderFieldValue (requestCFHTTPMessageRefVal, CFSTR ("Content-Length"), bodySizeCFStringRefVal)


If not using a read stream for the body, I add the body with
CFHTTPMessageSetBody (requestCFHTTPMessageRefVal, CFDataRefVal)

I set my callback for the stream with
CFReadStreamSetClient (streamStructPtr->requestCFReadStreamRefVal, streamEventOptionsVal, requestStreamEventProcess, &CFStreamClientContextVal)


I schedule the stream on a run loop with
CFReadStreamScheduleWithRunLoop (streamStructPtr- >requestCFReadStreamRefVal, CFRunLoopGetCurrent(), kCFRunLoopCommonModes)


Finaly, I open the stream with
CFReadStreamOpen (streamStructPtr->requestCFReadStreamRefVal)

That's it! Did I miss anything?

David Lalonde

Both of those should work. Do you know that the data is actually getting as far as the server (use tcpdump etc...)?

Fred

Hello All,

I am moving away from URLAcess and into CFNetwork, as I need to authenticate through a proxy server. This is the first time I use Core Foundation and CFNetwork and I have run into problems I know not how to resolve.

Here is the problem: My application sends a HTTP POST message to a PHP page. The PHP page echoes the received POST data. My application then outputs the HTTP response into a text file. When I look at the response file, I see no POST data.

I tried to set the message's body two ways: By using CFHTTPMessageSetBody, taking care of setting the "Content-Length" header field appropriately; By using CFReadStreamCreateForStreamedHTTPRequest, taking care of opening a read stream to the body data's content first.

Anyone have an idea as to what I am doing wrong?

_______________________________________________ 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

_______________________________________________ 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
References: 
 >CFNetwork, HTTP and POST messages (From: David Lalonde <email@hidden>)
 >Re: CFNetwork, HTTP and POST messages (From: Frederick Cheung <email@hidden>)
 >Re: CFNetwork, HTTP and POST messages (From: David Lalonde <email@hidden>)

  • Prev by Date: Re: CFNetwork, HTTP and POST messages
  • Next by Date: Re: URLAccess Stalls
  • Previous by thread: Re: CFNetwork, HTTP and POST messages
  • Next by thread: Re: CFNetwork, HTTP and POST messages
  • Index(es):
    • Date
    • Thread