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;
  • 相关阅读:
    leetcode_697. 数组的度
    645. 错误的集合
    leetcode_448. 找到所有数组中消失的数字
    leetcode_628. 三个数的最大乘积
    leetcode_414. 第三大的数
    leetcode_495. 提莫攻击
    leetcode_485. 最大连续1的个数
    在 Mac、Linux、Windows 下Go交叉编译
    Goland基本操作
    etcd搭建及基本使用
  • 原文地址:https://www.cnblogs.com/yuanxiaoping_21cn_com/p/2544032.html
Copyright © 2011-2022 走看看