如何使用Apache http客户端的URIBuilder在HTTP请求中发送正文?

时间:2015-10-19 09:11:28

标签: apache http curl apache-httpclient-4.x apache-httpcomponents

我知道我可以使用setParameter方法添加http参数,但如何使用URIBuilder类将正文传递给http请求?

例如,这个

URI uri = new URIBuilder().setScheme("http")
                .setHost("localhost:9091/test").setParameter("a", "1")
                .setParameter("b", "2").build();

等同于以下curl请求:

curl -X POST http://localhost:9091/test\?a\=1\&b\=2

但如何使用URIBuilder(或任何其他类)为以下卷曲构建网址:

curl -X POST http://localhost:9091/test -d '{"a":1,"b":2}'

1 个答案:

答案 0 :(得分:5)

v = datenum(2008, 1, 1):datenum(2010, 11, 31); % time vector
d = rand(1,length(v)); % data vector

fd = d;
alpha_o = 0.2;
for ii = 2:length(fd);
    fd(ii) = alpha_o.*fd(ii) + (1-alpha_o).*fd(ii-1);
end

plot(v,d); hold on; plot(v,fd);