GROOVY RESTClient实现:不带codeR发现请求的内容类型* / * [英] GROOVY RESTClient: No encoder found for request content type */*

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

问题描述

我正在休息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 */*

下面是我的code:

@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' ] )

我不知道,如果它的响应或不也许它的响应rencoding问题?在 * / * 有我担心,它甚至没有进行连接。当我在命令行中运行此作为一个curl命令它工作正常。
文件是需要为这个职位调用的唯一参数。

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.

感谢

推荐答案

请参照上<$ C文档$ C> HTTP建设者 。具体来说,

Refer docs on http-builder. Specifically,

由于我们从未设置的RESTClient实现实例默认内容类型
  或通过在该请求的contentType参数,RESTClient实现将把
  接受:/在请求报头,并解析基于响应
  无论是在响应Content-Type头给出。

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.

修改后()如下呼吁:

@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实现:不带codeR发现请求的内容类型* / *的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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