Re: HTTPS streams through a proxy

来源:互联网 发布:网络切换软件 编辑:程序博客网 时间:2024/06/11 18:45

转自: http://lists.apple.com/archives/macnetworkprog/2004/May/msg00040.html

Re: HTTPS streams through a proxy


  • SubjectRe: HTTPS streams through a proxy
  • From: Becky Willrich <email@hidden>
  • Date: Thu, 13 May 2004 17:03:26 -0700

We could use:
CFDictionaryRef proxyDict = SCDynamicStoreCopyProxies(NULL);

CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPProxy,
proxyDict);

But we need to be able to use specific proxy settings, independently
from the settings in the panel.

I am yet unsure on how to modify the proxyDict(if possible) so that it
would use the right settings for the proxy, or is there another way to
do this?

You are on the right track - CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPProxy, proxyDict) is the right call for configuring the HTTP(S) proxy; you just have to figure out what the right content for proxyDict is. If you just pass through SCDynamicStoreCopyProxies(NULL) as above, you get the default proxies as the user has configured them on the system. To create custom proxy settings, you can either make a mutable copy of the proxy dict returned by SCDynamicStoreCopyProxies() then change the settings you want, or you can create a new dictionary from scratch. To create a new dictionary from scratch, just use the keys given in CFHTTPStream.h. That will look something like this:

CFTypeRef keys[2], values[2];
keys[0] = kCFStreamPropertyHTTPSProxyHost;
values[0] = myHTTPSProxyHost;
keys[1] = kCFStreamPropertyHTTPSProxyPort;
values[1] = CFNumberCreate(NULL, kCFNumberSInt32Type, &myHTTPSProxyPortNumber);
proxyDict = CFDictionaryCreate(NULL, keys, values, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
CFReadStreamSetProperty(readStream, kCFStreamPropertyHTTPProxy, proxyDict);

This sets the HTTPS proxy to be whatever host is in myHTTPSProxyHost (should be a CFString) and whatever port is in myHTTPSProxyPortNumber.

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.

原创粉丝点击