用Rust发送原始数据作为HTTPS请求

huangapple go评论51阅读模式
英文:

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 是一个优秀的库,它提供了加密层,同时允许简单的 读取写入 操作。这里有一个优秀的示例,展示了如何实现我所需要的功能。

英文:

As per @tadmad's comment, rustls is a good library that provides an encryption layer and at the same time allows for simple reads and writes.
Here's an excellent example showing how to implement exactly what I was after.

huangapple
  • 本文由 发表于 2023年6月12日 03:09:02
  • 转载请务必保留本文链接:https://go.coder-hub.com/76452117.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定