Hello,
I created these RESTFul services :
<%pre>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
</%pre>
<%cpp>
if (request.getMethod() == "GET")
{
log_info("GET getBody() " << request.getBody());
}
else if (request.getMethod() == "POST")
{
log_info("POST getBody() " << request.getBody());
std::istringstream data(request.getBody());
std::cerr << data << std::endl;
}
else if (request.getMethod() == "PUT")
{
log_info("PUT getBody() " << request.getBody());
std::istringstream data(request.getBody());
std::cerr << data << std::endl;
}
else if (request.getMethod() == "DELETE")
{
log_info("DELETE getBody() " << request.getBody());
std::istringstream data(request.getBody());
std::cerr << data << std::endl;
}
else
{
throw std::runtime_error("Unknow method!");
}
</%cpp>
With this Perl program, all works fine :
use LWP::UserAgent;
my $url = 'http://localhost:8000/test';
my $bio = '{ "s": { "_str": "STRUCT", "_vec": [ 1, 2, 3, 4 ], "_int":
10 } }';
my $req = HTTP::Request->new(PUT => $url, HTTP::Headers->new, $bio);
$req->content_type('application/json');
$req->content_length(length $bio);
my $res = LWP::UserAgent->new->request($req);
print "PUT ", $res->status_line, "\n\n";
$req = HTTP::Request->new(GET => $url, HTTP::Headers->new, $bio);
$req->content_type('application/json');
$req->content_length(length $bio);
$res = LWP::UserAgent->new->request($req);
print "GET ", $res->status_line, "\n\n";
$req = HTTP::Request->new(POST => $url, HTTP::Headers->new, $bio);
$req->content_type('application/json');
$req->content_length(length $bio);
$res = LWP::UserAgent->new->request($req);
print "POST ", $res->status_line, "\n\n";
$req = HTTP::Request->new(DELETE => $url, HTTP::Headers->new, $bio);
$req->content_type('application/json');
$req->content_length(length $bio);
$res = LWP::UserAgent->new->request($req);
print "DELETE ", $res->status_line, "\n\n";
But with this cxxtools client, that does not work :
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <cxxtools/http/request.h>
#include <cxxtools/http/reply.h>
#include <cxxtools/http/client.h>
#include <cstdio>
using namespace cxxtools;
using namespace std;
int main(int argc, char *argv[])
{
ostringstream data;
data << "{ \"s\": { \"_str\": \"STRUCT\", \"_vec\": [ 1, 2, 3, 4 ],
\"_int\": 10 } }";
cxxtools::http::Request request("/test");
request.addHeader("Content-Type", "application/json");
request.method("PUT");
request.sendBody(data);
char buf[10];
std::sprintf(buf, "%d", data.str().size());
request.addHeader("Content-Length", buf);
cerr << buf << endl;
cxxtools::http::Client client("localhost", 8000);
client.execute(request);
cout << client.readBody();
return 0;
}
Have you a example for me ? :)
Thanks,
Jean-Michel
------------------------------------------------------------------------------
For Developers, A Lot Can Happen In A Second.
Boundary is the first to Know...and Tell You.
Monitor Your Applications in Ultra-Fine Resolution. Try it FREE!
http://p.sf.net/sfu/Boundary-d2dvs2
_______________________________________________
Tntnet-general mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tntnet-general