Using Charles and SSL Apple push address

2019-05-11 05:09发布

问题:

I have to confirm that my PHP code for sending push notification is working with a proxy. I installed Charles and I'm able to watch all my web traffic through a proxy (127.0.0.1:8888).

Now I would like to see if my script is correctly working for push notifications. I have :

stream_context_set_option($ctx, 'http', 'proxy', 'tcp://127.0.0.1:8888');
$fp = stream_socket_client('ssl://gateway.sandbox.push.apple.com:2195', $err,$errstr, 60, STREAM_CLIENT_CONNECT, $ctx);

I'm getting my push notification but I can't see what is happening in Charles. So my script is not using proxy ...

Do you know why ?

回答1:

This is because you passed a context with http options to stream_socket_client() - and more to the point you used an ssl:// wrapper instead of http:// or https://.

The stream_socket_*() functions do not know that you are implementing HTTP so they do not use the http context options - in order for this to work you would need to do e.g.

$fp = fopen('https://gateway.sandbox.push.apple.com:2195/path/to/file', 'r', false, $ctx);

This is probably a better idea anyway, because it is unlikely you would need the granular control that implementing HTTP manually would give you for the Apple APIs.