warmcat / libwebsockets

canonical libwebsockets.org networking library
https://libwebsockets.org
Other
4.75k stars 1.48k forks source link

How to deal with the parameters in the url of ws or wss?? #2508

Closed Clark-jhx closed 2 years ago

Clark-jhx commented 2 years ago

have below wss url wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iNDJhODZhZGE2NDQzZWNlMDVmMmE5MjM3MmViMzg5O......&date=Wed, 01 Dec 2021 08:54:18 GMT&host=iat-api.xfyun.cn

How should I handle the parameters in the url ?? authorization=YXBpX2tleT0iNDJhODZhZGE2NDQzZWNlMDVmMmE5MjM3MmViMzg5O......&date=Wed, 01 Dec 2021 08:54:18 GMT&host=iat-api.xfyun.cn

here is my code:

this->name = "wss";
this->host = "iat-api.xfyun.cn";
this->path = "/v2/iat";
this->port = 443;

if(this->name == "wss"){
     protocols[0] = {
        .name = "wss",
        .callback = connect_callback,
        .per_session_data_size = 0,
        .rx_buffer_size = MAX_PAYLOAD_SIZE,
    };
};
}else{
     protocols[0] = {
        .name = "ws",
        .callback = connect_callback,
        .per_session_data_size = 0,
        .rx_buffer_size = MAX_PAYLOAD_SIZE,
    };
}
protocols[1] = {
     NULL, NULL, 0
};

context_info = {0};
context_info.port = CONTEXT_PORT_NO_LISTEN;
context_info.iface = NULL;
context_info.protocols = protocols;
context_info.gid = -1;
context_info.uid = -1;
if(this->name == "wss"){
    context_info.options |= LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
}else if(this->name == "ws"){
    context_info.options |= LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME;
}

context = {0};
context = lws_create_context(&context_info);
connect_info = {0};
connect_info.context = context;
connect_info.protocol = this->name.c_str();
connect_info.address = this->host.c_str();
connect_info.port = this->port;
connect_info.path = this->path.c_str();
connect_info.host = this->host.c_str();
connect_info.origin =  this->host.c_str();
connect_info.userdata = (void *)this;
if (this->name == "wss") {
    connect_info.ssl_connection = LCCSCF_USE_SSL | LCCSCF_ALLOW_SELFSIGNED | LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK | LCCSCF_ALLOW_INSECURE | LCCSCF_ALLOW_EXPIRED;
} else if(this->name == "ws"){
    connect_info.ssl_connection = LCCSCF_SKIP_SERVER_CERT_HOSTNAME_CHECK; // 控制是否使用ssl
}

this->wsi = lws_client_connect_via_info(&connect_info);
Clark-jhx commented 2 years ago

Who can guide me, thanks very much.

lws-team commented 2 years ago

Just append it to connect_info.path, eg "/v2/iat?x=y&a=b"