LIBCURL 中的简单 telnet 示例 - C++
我需要在 LIBCURL (curl.haxx.se/libcurl) (C++) 中查找简单的 TELNET 示例 我搜索了这个网站,但没有找到任何简单的例子。 我只需要连接到 TELNET、进行身份验证并发送消息。
谢谢
I need to fing simple TELNET example in LIBCURL (curl.haxx.se/libcurl) (C++)
I searched over this site, but I don't found any simple example.
I need only to connect to TELNET, authenticate, and send message.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 libcurl 中您所能做的就是发送数据和接收数据。没有办法等待响应或根据响应发送数据。 libcurl 的全部目的是处理等待 HTTP 或 FTP 的数据和响应。
话虽如此,您也许可以使用
CURLOPT_READFUNCTION
和CURL_READFUNC_PAUSE
执行某些操作。从READFUNCTION
返回PAUSE
,然后在READFUNCTION
中看到“login:”时调用curl_easy_pause(CURLPAUSE_CONT)
。准备好在调用READFUNCTION
时返回您的用户名。我从来没有这样做过,所以我不能保证它是如何工作的。但从 API 描述来看,这似乎是正确的方法......
All you can do in libcurl is send data and recieve data. There is no way to wait for response or send data based on response. The whole point of libcurl is to handle waiting for data and responses for HTTP or FTP.
That being said, you may be able to do something with
CURLOPT_READFUNCTION
andCURL_READFUNC_PAUSE
. ReturnPAUSE
fromREADFUNCTION
, then callcurl_easy_pause(CURLPAUSE_CONT)
when you see "login:" in yourREADFUNCTION
. Be prepared to return your user name fromREADFUNCTION
when it gets called.I've never done this, so I can't vouch for how it works. But from API description, this seems to be the way to go...
注意:telnet 协议没有指定任何使用指定用户和密码登录的方式,因此curl 无法自动执行此操作。为此,您需要跟踪何时收到登录提示并相应地发送用户名和密码。
您可以在这里查看:http://www.cs.sunysb.edu/ Documentation/curl/index.html
也许你应该手动制作它,例如:
稍后它会询问你的用户名和密码。
NOTE: The telnet protocol does not specify any way to login with a specified user and password so curl can't do that automatically. To do that, you need to track when the login prompt is received and send the username and password accordingly.
You can look it here: http://www.cs.sunysb.edu/documentation/curl/index.html
Maybe you should make it manually like:
Later it will ask your username and password.