zoukankan      html  css  js  c++  java
  • poco之HttpRequest之post方法

    #import <iostream>
    #import <Poco/Net/HTTPClientSession.h>
    #import <Poco/Net/HttpRequest.h>
    #import <Poco/Net/HttpResponse.h>
    #import <Poco/URI.h>
    #import <Poco/Net/HTTPCredentials.h>
    #import <Poco/StreamCopier.h>
    #import <Poco/Net/HTMLForm.h>
    #import <Poco/BinaryReader.h>
    #import <Poco/StreamConverter.h>
    #import <Poco/Net/HTTPBasicCredentials.h>
    #import <string>
    #import <streambuf>

    std::string strURI = "http://192.168.41.1/entityemit/form.aspx"; 

        Poco::URI uri(strURI); 
        std::string path(uri.getPath());
       
        Poco::Net::HTTPClientSession session(uri.getHost(), uri.getPort());
        Poco::Net::HTTPRequest req(Poco::Net::HTTPRequest::HTTP_POST, path, Poco::Net::HTTPMessage::HTTP_1_1);
       
        // Add username and password (HTTP basic authentication) to the request.
        Poco::Net::HTTPBasicCredentials cred("domain\\uid", "password");
        cred.authenticate(req);
       
        Poco::Net::HTMLForm form;
        form.set("uid", "yxp");
       
        // Send the request.
        form.prepareSubmit(req);
        std::ostream& ostr = session.sendRequest(req);
        form.write(ostr);
       
        // Receive the response.
        Poco::Net::HTTPResponse res;
        std::istream& rs = session.receiveResponse(res);

        std::string responseText;
        Poco::StreamCopier copier;
        copier.copyToString(rs, responseText);
        std::cout << responseText << std::endl;
  • 相关阅读:
    python的虚拟环境管理
    树的转换
    表达式·表达式树·表达式求值
    找和为K的两个元素
    最大奇数与最小偶数之差的绝对值
    L1-026 I Love GPLT (5分)
    L1-025 正整数A+B (15分)
    L1-024 后天 (5分)
    L1-023 输出GPLT (20分)
    L1-022 奇偶分家 (10分)
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/2544032.html
Copyright © 2011-2022 走看看