GET是HTTP协议支持的众多请求方法之一。当客户端需要从服务器获取数据作为request-URI的一部分时,使用GET请求方法。
我有一个 C# 中的 get 请求,我需要将其转换为 C++ (boost) C# 中的获取请求: 使用系统文本; 使用Newtonsoft.Json; 班级计划 { 私有静态只读字符串键=“ 我有一个 C# 中的 get 请求,我需要将其转换为 C++ (boost) 在 C# 中获取请求: using System.Text; using Newtonsoft.Json; class Program { private static readonly string key = "<your-translator-key>"; private static readonly string endpoint = "https://api.cognitive.microsofttranslator.com"; // location, also known as region. // required if you're using a multi-service or regional (not global) resource. It can be found in the Azure portal on the Keys and Endpoint page. private static readonly string location = "<YOUR-RESOURCE-LOCATION>"; static async Task Main(string[] args) { // Input and output languages are defined as parameters. string route = "/translate?api-version=3.0&from=en&to=fr&to=zu"; string textToTranslate = "I would really like to drive your car around the block a few times!"; object[] body = new object[] { new { Text = textToTranslate } }; var requestBody = JsonConvert.SerializeObject(body); using (var client = new HttpClient()) using (var request = new HttpRequestMessage()) { // Build the request. request.Method = HttpMethod.Post; request.RequestUri = new Uri(endpoint + route); request.Content = new StringContent(requestBody, Encoding.UTF8 "application/json"); request.Headers.Add("Ocp-Apim-Subscription-Key", key); // location required if you're using a multi-service or regional (not global) resource. request.Headers.Add("Ocp-Apim-Subscription-Region", location); // Send the request and get response. HttpResponseMessage response = await client.SendAsync(request).ConfigureAwait(false); // Read response as a string. string result = await response.Content.ReadAsStringAsync(); Console.WriteLine(result); } } } 在boost中获取请求:https://www.boost.org/doc/libs/1_67_0/libs/beast/doc/html/beast/quick_start.html 由于额外输入数据量巨大,不清楚如何使用它们 这应该是一个好的开始: #include <boost/asio/ssl.hpp> #include <boost/beast.hpp> #include <boost/beast/ssl.hpp> #include <boost/json.hpp> #include <iostream> namespace net = boost::asio; namespace beast = boost::beast; namespace http = beast::http; namespace ssl = net::ssl; namespace json = boost::json; using tcp = net::ip::tcp; int main() { std::string const my_translator_key = "YOUR_TRANSLATOR_KEY"; std::string const my_resource_location = "westus"; net::io_context ioc; tcp::resolver resolver{ioc}; auto eps = resolver.resolve("api.cognitive.microsofttranslator.com", "https"); // Input and output languages are defined as parameters. std::string route = "/translate?api-version=3.0&from=en&to=fr&to=zu"; std::string textToTranslate = "I would really like to drive your car around the block a few times!"; json::array body = {{{"Text", textToTranslate}}}; std::string requestBody = json::serialize(body); http::request<http::string_body> request; request.method(http::verb::post); request.target(route); request.set(http::field::content_type, "application/json"); request.set(http::field::user_agent, "Beast"); request.set(http::field::accept, "application/json"); request.set(http::field::host, "api.cognitive.microsofttranslator.com"); request.set(http::field::authorization, "Ocp-Apim-Subscription-Key: " + my_translator_key); request.set(http::field::authorization, "Ocp-Apim-Subscription-Region: " + my_resource_location); request.body() = requestBody; request.prepare_payload(); tcp::socket s{ioc}; net::connect(s, eps); ssl::context ctx{ssl::context::tlsv12_client}; boost::beast::ssl_stream<tcp::socket> stream{std::move(s), ctx}; stream.handshake(ssl::stream_base::client); http::write(stream, request); beast::flat_buffer buffer; http::response<http::string_body> response; http::read(stream, buffer, response); std::cout << response.body() << std::endl; } 显然没有端点密钥我无法测试它:
我有一个 get 请求,通过空手道框架运行时返回 404,但相同的请求在邮递员上返回 200。 示例获取请求 - test/messageid 消息 ID 来自另一个对
尝试编写一个简单的解析器来获取我的机器人的信息。代码很简单。但作为回报,我只得到“您无权访问此资源。”不是我看到的源代码...
如何在 Yii2 RESTful 服务中验证来自 GET 请求的参数
我有一个语言参数需要发送到我的文档端点。所以我必须验证用户是否在他的 GET 请求中发送了这个参数。 在我的模型中制定规则没有做任何事情: p...
我需要将文件的扩展名存储在VBA中的变量中, 我现在所做的是 文件=你好.pdf 扩展名 = split(文件,".")(1) 但有时我的文件可能像 file = 1.Filen...
前端代码中存在 XMLHTTPRequest 是否存在问题?
此功能可在浏览器中查看。我担心有人可以以某种方式访问该文件夹并操纵数据库。我可以在前端保持此打开状态还是需要在后端保护它?
Java HTTP GET 请求给出 403 Forbidden,但在浏览器中有效
我有一些代码,旨在通过 HTTP 向服务器发送 GET 请求,并在那里获取数据。我还没有编写与响应相关的部分,因为我首先想测试......
isset 可以与 CodeIgniter 的 get 方法一起使用吗?
使用 CodeIgniter 我试图查看 URL 中的“ID”是否是“uID”(用户 ID)或“sID”(系统 ID)。 我正在使用的代码是: if(isset($this->input->get('uID'))) { $getID = $this-inp...
获取页面QWebEngineView Python的cookie
我正在用python创建一个浏览器,我想知道如何从网页中恢复cookie,无论我搜索多少,我都不明白这是怎么可能的 我有这个代码: 导航 =
所以我想问这样的问题并寻求建议。如果有经验的开发人员给出他们的意见,我将非常高兴。预先感谢您<<3 So I have displayed the products from the user's ...
我想尝试获取当前连接的WiFi的SSID,我如何在React JS中做到这一点,有人尝试过吗?但在这种情况下,没有API或后端提供获取数据 可以获得...
使用 GET 请求 jQuery 获取数据到单选选项和选择框
我正在尝试做一个汽车品牌和型号选择框,因此当您选择汽车收音机选项时,它会显示汽车、品牌、型号和年份的所有可用选择。 我正在尝试使用 GitHub 链接,但我...
使用http_poller从非本地的elasticsearch主机请求某些内容
我想问是否有一种方法可以使用http_poller从非本地的elasticsearch主机请求某些内容。就像下面这样: 输入 { http_poller { 网址=> { es_data =>...
我已经尝试了很长一段时间来获取 php 文件上特定产品的价格,但我找不到解决方案。我已经尝试过使用 woocommerce 短代码,但我总是在我的目录中获得完整的产品...
这里有一个表单,当使用两个子选择之一选择“Dst Output”按钮时,提交后将返回 .dat 文件(在本例中只是一个文本文件)...
Heroku Node.js 后端与 React 前端的工作方式与本地的工作方式不同,尽管有 Procfile
我有一个带有 Node.js 后端的 React 网站,该网站通过我的 GitHub 帐户部署到 Heroku。 React 网站前端将联系表单请求发送回 Node.js 后端服务器,这......
当我尝试获取亚马逊销售合作伙伴订单并且订单数量超过 100 个时,我只收到 100 个订单。如何获取下一页订单? 我需要检查亚马逊销售合作伙伴
使用mockito验证NavigationService popUntil调用
我正在为我的 flutter 移动应用程序编写单元测试,并且我正在尝试测试一个函数,该函数在执行时应弹出返回堆栈,直到满足路由函数的谓词。 ...
LWC 设置器没有被调用。 {消息}1。 getter 值:{displayMessage}2。设置器值:{updatedMessage} 导入 {
如何通过 GET 请求关闭 Rest Assured/Java 中的“自动遵循重定向”?
我已经在这个问题上坚持了几个星期了(我对放心完全陌生),我需要社区的帮助。 我的问题是我正在尝试向 oauth2/authorize 端点发出 GET 请求,