warmcat / libwebsockets

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

I found that the test-client.c program will truncate the url, so the handshake fails, why #2719

Closed coldlapy closed 2 years ago

coldlapy commented 2 years ago

When executing the following command: ./libwebsockets-test-client wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMGQ0MDI2NjRlM2VlOWMwZmNlZmI1NDc5YWRmZGRlMDkiLCBhbGdvcml0aG0 9ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iSWRZdis3NjhxSmJNdGZZMkxWRzJqRVpVbEMzQm9qdEo2YmNjV1E1ZGdTST0i&date=Tue,%2030%20Aug%202022%2007:41:33%20GMT&host=iat-api.xfy un.cn --ssl

lws_client_connect_info i is i.path = "/v2/iat?authorization=YXBpX2tleT0iMGQ0MDI2NjRlM2VlOWMwZmNlZmI1NDc5YWRmZGRlMDkiLCBhbGdvcml0aG0 9ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iSWRZdis3NjhxSmJNdGZZMkxWRzJqRVpVbEMzQm9qdEo2YmNjV1E1ZGdTST0i";

The following string ("&date=Tue%2C%2030%20Aug%202022%2006%3A09%3A09%20GMT&host=iat-api.xfyun.cn") is lost, so the handshake fails.

Found after continuing to add log files, at the beginning of the program, the argv[1] is "wss://iat-api.xfyun.cn/v2/iat?authorization=YXBpX2tleT0iMGQ0MDI2NjRlM2VlOWMwZmNlZmI1NDc5YWRmZGRlMDkiLCBhbGdvcml0aG09ImhtYWMtc2hhMjU2IiwgaGVhZGVycz0iaG9zdCBkYXRlIHJlcXVlc3QtbGluZSIsIHNpZ25hdHVyZT0iSWRZdis3NjhxSmJNdGZZMkxWRzJqRVpVbEMzQm9qdEo2YmNjV1E1ZGdTST0i";

That is to say, argv[1] has lost the string, why? please help... thanks

lws-team commented 2 years ago

If your commandline has & in it, your shell will interpret it. You must put the whole argument in quotes like "xyz&abc" for the shell to deliver it without splitting it itself (and telling you weird errors like can't find date=Tue... or whatever).

coldlapy commented 2 years ago

thank you very much for your enthusiastic answer, I have benefited a lot.