Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
benharbit opened this issue May 17, 2017 · 19 comments

Comments

@benharbit
Copy link

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?

@xionghui19920922
Copy link

Have you solved this problem?

@austinpaine
Copy link

Also hoping for an answer

@davidstl
Copy link

davidstl commented Sep 4, 2018

Getting the same thing too. Anyone has an update?

@madsurgeon
Copy link

I have the same problem.

@j-fab
Copy link

j-fab commented Feb 17, 2019

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

@j-fab
Copy link

j-fab commented Feb 20, 2019 via email

@chunqiulfq
Copy link

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.

@wangbing8895
Copy link

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

@zak905
Copy link

zak905 commented Feb 4, 2021

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 /

@wensheng-zhang
Copy link

verify_certificate

Could you list the function and paramters? thanks

@warrially
Copy link

怎么解决的? 求留言

@wensheng-zhang
Copy link

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

@warrially
Copy link

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

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

@wensheng-zhang
Copy link

share 一下

@warrially
Copy link

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
Copy link

/// 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());

@Kevinlinpr
Copy link

/// 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");就好了,不需要去改源码

@yashasweeyash
Copy link

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

@wang01234
Copy link

wang01234 commented Mar 3, 2023

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 );

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests