gpt4 book ai didi

java - GROOVY RESTClient : No encoder found for request content type */*

转载 作者:行者123 更新时间:2023-12-02 13:24:21 24 4
gpt4 key购买 nike

我正在运行休息 POST 请求,但在编译时收到此错误:

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 是此 post 调用所需的唯一参数。

谢谢

最佳答案

Refer docs on http-builder 。具体来说,

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
)

关于java - GROOVY RESTClient : No encoder found for request content type */*,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29570451/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com