使用 Jersey 客户端进行 POST 操作 [英] Using the Jersey client to do a POST operation

查看:37
本文介绍了使用 Jersey 客户端进行 POST 操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Java 方法中,我想使用 Jersey 客户端对象在 RESTful Web 服务(也使用 Jersey 编写)上执行 POST 操作,但我不确定如何使用客户端发送值在服务器上用作 FormParam.我可以很好地发送查询参数.

In a Java method, I'd like to use a Jersey client object to do a POST operation on a RESTful web service (also written using Jersey) but am not sure how to use the client to send the values that will be used as FormParam's on the server. I'm able to send query params just fine.

推荐答案

我自己还没做过,但 Google-Fu 的一个快速位揭示了一个 blogs.oracle.com 上的技术提示,并附有您所要求的示例.

Not done this yet myself, but a quick bit of Google-Fu reveals a tech tip on blogs.oracle.com with examples of exactly what you ask for.

来自博客文章的示例:

MultivaluedMap formData = new MultivaluedMapImpl();
formData.add("name1", "val1");
formData.add("name2", "val2");
ClientResponse response = webResource
    .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE)
    .post(ClientResponse.class, formData);

有什么帮助吗?

这篇关于使用 Jersey 客户端进行 POST 操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆