英文:
Send raw data as an HTTPS request with Rust
问题
我想通过发送原始数据来进行HTTPS请求。原则上应该是这样的:https://stackoverflow.com/questions/23346757/make-http-request-in-rust-using-std
但是,我想要使用SSL来实现它。
对我来说很重要的是,我不想像通常使用reqwests
一样使用不同的方法来“构建”请求。我想要的是简单地获取一些数据,就像下面的示例一样,然后通过HTTPS发送到服务器。
示例GET:
GET /index.php HTTP/1.1\r\nHost: www.server.com\r\n
示例POST:
POST /index.php HTTP/1.1\r\nHost: www.server.com\r\nContent-Length:14\r\n\r\nsomepostdata=1
编辑:
请注意,我不想自己实现SSL(显然!)。我需要一个简单的API,可以让我制作请求(如上所示)并将其通过HTTPS发送到Web服务器(就像我在HTTP上使用telnet一样)。希望这一点是清楚的(基于一些评论中一些人表达的疑虑)。
英文:
I would like to make an HTTPS request by sending raw data to it. In principle it would be something like this: https://stackoverflow.com/questions/23346757/make-http-request-in-rust-using-std
However, I would like to do it with SSL.
It is important to me that I don't have to "build" a request like you normally do with reqwests
using different method. What I'm after is to simply get some data, like an example below, and send it via HTTPS to a server.
Example GET:
GET /index.php HTTP/1.1\r\nHost: www.server.com\r\n
Example POST:
POST /index.php HTTP/1.1\r\nHost: www.server.com\r\nContent-Length:14\r\n\r\nsomepostdata=1
EDIT:
Note that I don't want to do my own SSL implementation (obviously!). I'm after a simple API that would let me craft the request (as presented above) and send it to a web server using HTTPS (as if I was using telnet on HTTP). Hope that's clear (based on the doubts some expressed via their comments).
答案1
得分: 2
根据 @tadmad 的评论,rustls 是一个优秀的库,它提供了加密层,同时允许简单的 读取
和 写入
操作。这里有一个优秀的示例,展示了如何实现我所需要的功能。
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论