#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;
posted on 2012-06-10 15:40  袁晓平  阅读(5288)  评论(0编辑  收藏  举报