第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何在 C++ 服務(wù)器中解碼 curl url 編碼的字符串

如何在 C++ 服務(wù)器中解碼 curl url 編碼的字符串

PHP
泛舟湖上清波郎朗 2021-09-18 11:06:21
我正在使用 c++ pastiche rest api 庫在 ubuntu linux 中制作一個 rest api。我已經(jīng)讓服務(wù)器正常工作了。我可以使用 php curl 將數(shù)據(jù)發(fā)布到我的服務(wù)器。服務(wù)器接收到數(shù)據(jù),可以返回數(shù)據(jù)。問題是這個。當(dāng)我使用 curl post 發(fā)布到服務(wù)器時,它以這樣的 url 編碼字符串將其發(fā)送到服務(wù)器name=percy&age=34&eye_color=blue。我需要知道如何在 C++ 中將每一個都放入一個字符串中。此外,字段之一也可能具有二進(jìn)制數(shù)據(jù)以及普通字符串。我已經(jīng)編寫了解釋二進(jìn)制數(shù)據(jù)的代碼,但我現(xiàn)在不知道如何從 curl post 轉(zhuǎn)換字符串。請忽略我的端口在我的 php.ini 中不同的事實(shí)。原因是我在 virtualbox 中運(yùn)行 ubuntu。我需要從我發(fā)送的帖子中提取字符串和二進(jìn)制數(shù)據(jù)。這是我不知道該怎么做。我不確定我是否需要另一個圖書館來做到這一點(diǎn)這是我的 php 代碼:-$postData = http_build_query(            array(                'dstdata' => 'hello',                'more' => 'test',                'age' => 34            )        );$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'localhost:9999/about');        curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");        curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);        $output = curl_exec($ch);        print_r($output);               curl_close($ch);上面的代碼會生成一個這樣的字符串 dstdata=hello&more=test&age=34這里是 C++ 服務(wù)器代碼。你可以看到我在這里設(shè)置了兩條路線:-#include <pistache/router.h>#include "pistache/endpoint.h"#include "pistache/http.h"#include <iostream>using namespace Pistache;using namespace Rest;Rest::Router router;void sausage(const Rest::Request& request, Http::ResponseWriter response){    std::cout << "We have contact" << std::endl;    response.send(Http::Code::Ok, "Bottoms Up\n");}void about(const Rest::Request& request, Http::ResponseWriter response){    std::cout << "Server Running" << std::endl;    response.send(Http::Code::Ok, request.body());}int main(){    Routes::Get(router,"/ready",Routes::bind(&sausage));    Routes::Post(router,"/about",Routes::bind(&about));    Pistache::Address addr(Pistache::Ipv4::any(), Pistache::Port(9080));    auto opts = Pistache::Http::Endpoint::options()        .threads(10).flags(        Pistache::Tcp::Options::ReuseAddr);    Http::Endpoint server(addr);    server.init(opts);    server.setHandler(router.handler());    server.serve();    return 0;}   
查看完整描述

1 回答

  • 1 回答
  • 0 關(guān)注
  • 370 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號