mirror of
https://github.com/Syping/dtranslatebot.git
synced 2026-04-21 14:40:41 +02:00
add http_header class and bot::http namespace
This commit is contained in:
parent
f12e13ed28
commit
e98bd9de6c
14 changed files with 185 additions and 72 deletions
|
|
@ -17,9 +17,10 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <dpp/json.h>
|
||||
#include <dpp/httpsclient.h>
|
||||
#include <iostream>
|
||||
#include "../../core/http_request.h"
|
||||
#include "deepl.h"
|
||||
using namespace bot::http;
|
||||
using namespace bot::translator;
|
||||
using namespace std::chrono_literals;
|
||||
|
||||
|
|
@ -43,7 +44,8 @@ const std::vector<language> deepl::get_languages()
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true), { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
|
||||
http_response response = request.get(http_request::legacy_url(m_hostname, 443, "/v2/languages?type=target", true),
|
||||
{{"Authorization", "DeepL-Auth-Key " + m_apiKey}});
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_array()) {
|
||||
|
|
@ -91,7 +93,8 @@ const std::string deepl::translate(const std::string &text, const std::string &s
|
|||
|
||||
try {
|
||||
http_request request;
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(), "application/json", { {"Authorization", "DeepL-Auth-Key " + m_apiKey} });
|
||||
http_response response = request.post(http_request::legacy_url(m_hostname, 443, "/v2/translate", true), json_body.dump(),
|
||||
{{"Authorization", "DeepL-Auth-Key " + m_apiKey}, {"Content-Type", "application/json"}});
|
||||
if (response.status == 200) {
|
||||
const dpp::json json_response = dpp::json::parse(response.content);
|
||||
if (json_response.is_object()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue