D
D
Dmitry2020-08-20 16:24:27
PHP
Dmitry, 2020-08-20 16:24:27

How to make requests through sockets and proxies to wss (websocket)?

Good day.
You need to connect to the server via wss and be sure to use a certain http proxy
, you can make a socks5 proxy, but you haven’t figured out how to fasten it.
I do like this:

$sp = stream_socket_client("proxy:ip", $errno, $errstr, $timeout, STREAM_CLIENT_CONNECT , $context);
      $write = "CONNECT host.com:443 HTTP/1.1\r\n";
      $write .= "HOST: host.com\r\n";
      $write .= "\r\n";
      fwrite($sp, $write);

If without a proxy, then everything works.

The connection to the proxy is established, and then I get "400 The plain HTTP request was sent to HTTPS port"
I understand that the request is not encoded and just text, but how else?
I tried the same thing on node js, everything started right away, but it is VERY desirable in PHP

There are not many ready-made solutions for working with wss

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nokimaro, 2020-08-20
@pilip

1. you need socks4 / socks5 / HTTP tunnel
2. you can't just put socks proxy in stream_socket_client. But if you really want to, then it's done like this - https://github.com/weheartwebsites/SOCKS5/blob/mas... I
suggest using a ready-made and proven websocket client https://github.com/ampp/websocket-client
that in proxy https://github.com/ampp/websocket-client/issues/24

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question