• 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: Proxy Problem with CFNetwork
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Proxy Problem with CFNetwork


  • Subject: Re: Proxy Problem with CFNetwork
  • From: Becky Willrich <email@hidden>
  • Date: Wed, 29 Oct 2003 11:21:39 -0800

I'm creating an CFHTTPMessageRef using CFHTTPMessageCreateRequest() passing in my https url and POST for the method. I then set some headers and call CFReadStreamCreateForHTTPRequest to create a stream. Once I have the stream, here's how I'm setting the proxy settings:

CFDictionaryRef theProxyDict = SCDynamicStoreCopyProxies(NULL);
if (theProxyDict != NULL) {
CFReadStreamSetProperty(my_stream, kCFStreamPropertyHTTPProxy, theProxyDict);
}

This should work; your code is correct. This is also more or less what Safari does; an interesting test would be to make sure that Safari can reach the given URL, and that Safari is in fact talking through the proxy (is not connecting directly to the server). If Safari works, you can fairly safely assume there's a bug somewhere in your code. If Safari does not work, the bug is in CFNetwork. In that case, make sure you're on 10.2.6 or later (some bugs in this area were fixed for 10.2.6), then please let us know.

Then I do a CFReadStreamOpen(my_stream), but it does not make the connection to the proxy server.

The opening of a socket to the proxy may not occur promptly upon calling CFReadStreamOpen() - it takes some time to look up the DNS entry for the proxy, for instance. If you've waited a few seconds and still don't have a connection, though, that's a problem. Also, nothing will progress unless you somehow give the stream computational time. There are 3 ways to do that, depending on your overall threading model. First and best, set yourself up for event -driven control of the stream by setting yourself as the client on the stream, then schedule the stream on a run loop, then run that run loop. Second, for a polling model, call CFReadStreamHasBytesAvailable() periodically - that will give the stream time to advance the state of the underlying connection. Third, for a blocking model, just call CFReadStreamRead(); that call blocks (advancing the internal state of the stream and underlying connection) until bytes become available.

I verified that the Dictionary that is returned from SCDynamicStoreCopyProxies() does in fact have a key for the HTTPS proxy host and port.

Check also that the HTTPSProxyEnabled key is either absent or set to "1". Finally, verify that the proxy exception list is empty or the URL you're downloading doesn't match the exception list.

I also tried setting the proxy settings using the following code as well with no better luck:

CFStringRef proxyHostRef = CFStringCreateWithCString(NULL, (const char *)&proxyHost, kCFStringEncodingMacRoman);
CFReadStreamSetProperty(my_stream, kCFStreamPropertyHTTPSProxyHost, proxyHostRef);
SInt32 proxyPortFull = proxyPort;
CFNumberRef proxyPortRef = CFNumberCreate(NULL, kCFNumberSInt32Type, &proxyPortFull);
CFReadStreamSetProperty(my_stream, kCFStreamPropertyHTTPSProxyPort, proxyPortRef);

This will not work; CFNetwork expect a full dictionary under the property kCFStreamPropertyHTTPProxy.

I even tried creating a whole new Dictionary, by pulling out the ProxyHost and ProxyPort key/value pair from the dictionary returned by SCDynamicStoreCopyProxies() and then using the newly created dictionary to set the proxy property, but that did not work either.

This also should have worked.

I don't understand why this is not working like it is described in the documentation. Am I doing anything wrong here? Anyone have some sample code that does this?

Take a look at /Developer/Examples/Networking/URLLoad; it has a panel that allows the user to configure the proxy. You can look at it to see how it passes the proxy info down to the stream, then uses the stream. It doesn't show just grabbing the proxy dictionary from SystemConfiguration, but it looks like you are doing that part correctly.

Hope that helps,
REW
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.

References: 
 >Proxy Problem with CFNetwork (From: Daniel Zimmerman <email@hidden>)

  • Prev by Date: Re: Proxy Problem with CFNetwork
  • Next by Date: Re: Proxy Problem with CFNetwork
  • Previous by thread: Re: Proxy Problem with CFNetwork
  • Next by thread: Re: Proxy Problem with CFNetwork
  • Index(es):
    • Date
    • Thread