websocketpp icon indicating copy to clipboard operation
websocketpp copied to clipboard

Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)

Open benharbit opened this issue 7 years ago • 19 comments

I get the following error when I try to connect.

Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)

How would I get the actual response from the server or understand what is going wrong?

benharbit avatar May 17 '17 18:05 benharbit

Have you solved this problem?

xionghui19920922 avatar Jun 13 '18 05:06 xionghui19920922

Also hoping for an answer

austinpaine avatar Jun 13 '18 20:06 austinpaine

Getting the same thing too. Anyone has an update?

davidstl avatar Sep 04 '18 12:09 davidstl

I have the same problem.

madsurgeon avatar Jan 22 '19 20:01 madsurgeon

I have this same issue when running the print_client example. Can anyone help please?

j-fab avatar Feb 17 '19 16:02 j-fab

Thank you so much David. I got the print_client_tls working by disabling the verify_certificate function, but this print_client issue remains.


From: David St-Louis [email protected] Sent: Tuesday, February 19, 2019 8:40:13 PM To: zaphoyd/websocketpp Cc: Jacob Jiang; Mention Subject: Re: [zaphoyd/websocketpp] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.) (#648)

@j-fabhttps://github.com/j-fab I got WebSockets working as both client and server, so I solved this. Let me dig in my commit history and I'll come back to you.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/zaphoyd/websocketpp/issues/648#issuecomment-465113384, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ArzreI_jJh1LH9EADM90RZp20Aa8SktHks5vO_CtgaJpZM4NeP-T.

j-fab avatar Feb 20 '19 03:02 j-fab

hi, I encountered this error message during the use of socket.io-client-cpp. The problem I encountered was that the ssl was not compiled, the https used when setting the url was wrong, and it returned to normal when I used http. Hope to be helpful to this problem.

chunqiulfq avatar Jan 17 '20 02:01 chunqiulfq

@chunqiulfq I also meet this problem.did you build socket.io-client-cpp with boost?

wangbing8895 avatar Jan 15 '21 08:01 wangbing8895

in my case, it was just due a difference in the path, my socket io server was listening on /path and the client was connection on /

zak905 avatar Feb 04 '21 15:02 zak905

verify_certificate

Could you list the function and paramters? thanks

wensheng-zhang avatar Mar 17 '21 12:03 wensheng-zhang

怎么解决的? 求留言

warrially avatar Apr 09 '21 01:04 warrially

@warrially 看一下 监听路径 和 连接路径 是否完全匹配。 如果监听的是wss://192.168.0.100:8008/ws/, 而客户端连接的时候,缺使用了wss://192.168.0.100:8008/ws。少了一个斜线。 zak905表达的应该就是这个意思吧。

wensheng-zhang avatar Apr 09 '21 01:04 wensheng-zhang

@warrially 看一下 监听路径 和 连接路径 是否完全匹配。 如果监听的是wss://192.168.0.100:8008/ws/, 而客户端连接的时候,缺使用了wss://192.168.0.100:8008/ws。少了一个斜线。 zak905表达的应该就是这个意思吧。

已经搞定了, 知道是什么原因了. 他这个库有问题. 少了Origin, 在源码里加上就好了., 谢谢

warrially avatar Apr 09 '21 06:04 warrially

share 一下

wensheng-zhang avatar Apr 09 '21 06:04 wensheng-zhang

share 一下

template void connection::send_http_request() {     m_alog->write(log::alevel::devel,"connection send_http_request");

    // TODO: origin header?  这里tmd偷工减料?   这河里妈?

    // Have the protocol processor fill in the appropriate fields based on the     // selected client version     if (m_processor) {         lib::error_code ec;         ec = m_processor->client_handshake_request(m_request,m_uri,             m_requested_subprotocols);

        if (ec) {             log_err(log::elevel::fatal,"Internal library error: Processor",ec);             return;         }     } else {         m_elog->write(log::elevel::fatal,"Internal library error: missing processor");         return;     }

warrially avatar Apr 09 '21 06:04 warrially

/// Fill in a set of request headers for a client connection request
/**
 * @param [out] req  Set of headers to fill in
 * @param [in] uri The uri being connected to
 * @param [in] subprotocols The list of subprotocols to request
 */
lib::error_code client_handshake_request(request_type & req, uri_ptr
    uri, std::vector<std::string> const & subprotocols) const
{
    req.set_method("GET");
    req.set_uri(uri->get_resource());
    req.set_version("HTTP/1.1");

	req.append_header("Origin", "http://www.baidu.com/"); // 在这里补上 Origin 后正常
	// add origin and fix it ..

    req.append_header("Upgrade","websocket");
    req.append_header("Connection","Upgrade");
    req.replace_header("Sec-WebSocket-Version","13");
    req.replace_header("Host",uri->get_host_port());

warrially avatar Apr 09 '21 06:04 warrially

/// Fill in a set of request headers for a client connection request
/**
 * @param [out] req  Set of headers to fill in
 * @param [in] uri The uri being connected to
 * @param [in] subprotocols The list of subprotocols to request
 */
lib::error_code client_handshake_request(request_type & req, uri_ptr
    uri, std::vector<std::string> const & subprotocols) const
{
    req.set_method("GET");
    req.set_uri(uri->get_resource());
    req.set_version("HTTP/1.1");

	req.append_header("Origin", "http://www.baidu.com/"); // 在这里补上 Origin 后正常
	// add origin and fix it ..

    req.append_header("Upgrade","websocket");
    req.append_header("Connection","Upgrade");
    req.replace_header("Sec-WebSocket-Version","13");
    req.replace_header("Host",uri->get_host_port());

路径错了就会导致这个报错,而且 client::connection_ptr 下有append_header con->append_header("Origin", "xxxxxx");就好了,不需要去改源码

Kevinlinpr avatar Sep 03 '21 02:09 Kevinlinpr

For me using the encoded URL solved the problem. I am not sure when I am going to find time to code a proper fix for this repository, but meanwhile following should help or at least send some of you in the right direction (hopefully).

if the problematic url is: wss://ws.host.com/?api_key=someApiKeyContaining/+=Etc&enctoken=someEncTokenContaining/+=Etc

then following encoded url should work: wss://ws.host.com/?api_key=someApiKeyContaining%2F%2B%3DEtc&enctoken=someEncTokenContaining%2F%2B%3DEtc

yashasweeyash avatar Oct 13 '21 22:10 yashasweeyash

Settle in this way.

client::connection_ptr con = echo_client.get_connection( uri, ec ); con->append_header("access-control-allow-origin", "*"); echo_client.connect( con );

wang01234 avatar Mar 03 '23 10:03 wang01234