GROOVY RESTClient:找不到请求内容类型的编码器 */* [英] GROOVY RESTClient: No encoder found for request content type */*

查看:23
本文介绍了GROOVY RESTClient:找不到请求内容类型的编码器 */*的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个 rest POST 请求,但在编译时出现此错误:

I am running a rest POST request and I am getting this error when I compile:

Caught: java.lang.IllegalArgumentException: No encoder found for request content type */*

这是我的代码:

@Grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.7' )
import groovyx.net.http.RESTClient
def client = new RESTClient( 'http://localhost' )
def resp = client.post( path : '/services/adi/validateadimeta/fromfile',body : [ file:'foo' ] )

我不确定它是否响应可能是响应的重新编码问题?*/* 让我担心它甚至没有建立连接.当我在命令行上将它作为 CURL 命令运行时,它工作正常.file 是此发布调用所需的唯一参数.

I am not sure if its responding or not maybe its a rencoding problem with the response? The */* has me concerned that its not even making a connection. When I run this as a CURL command on the commandline it works fine. file is the only parameter needed for this post call.

谢谢

推荐答案

参考 上的文档http-builder.具体来说,

因为我们从未在 RESTClient 实例上设置默认内容类型或者在这个请求中传递一个 contentType 参数,RESTClient 将把Accept:/在请求头中,并根据响应内容类型标头中给出的任何内容.

Since we never set a default content-type on the RESTClient instance or pass a contentType argument in this request, RESTClient will put Accept: / in the request header, and parse the response based on whatever is given in the response content-type header.

修改,post()调用如下:

@Grab('org.codehaus.groovy.modules.http-builder:'http-builder:0.7' )
import groovyx.net.http.RESTClient
import static groovyx.net.http.ContentType.*

def client = new RESTClient( 'http://localhost' )
def resp = client.post( 
    path: '/services/adi/validateadimeta/fromfile',
    body : [ file : 'foo' ],
    requestContentType : JSON 
)

这篇关于GROOVY RESTClient:找不到请求内容类型的编码器 */*的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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