我坚持在POST请求体中添加JSON.没有任何方法可以设置请求的主体.
有什么方法可以实现这一点.否则我不得不放弃使用Jetty.
这是我发出POST请求的方式:
Request request = httpClient.POST(url);
        //request.method(HttpMethod.POST);
        request.header(HttpHeader.ACCEPT, "application/json");
        request.header(HttpHeader.CONTENT_TYPE, "application/json");
        // Add basic auth header if credentials provided
        if (isCredsAvailable()) {
            String authString = username + ":" + password;
            byte[] authEncBytes = Base64.getEncoder().encode(authString.getBytes());
            String authStringEnc = "Basic " + new String(authEncBytes);
            request.header(HttpHeader.AUTHORIZATION, authStringEnc);
        }
        request(send);
任何帮助表示赞赏!
我能够自己解决这个问题.解决方案一直盯着我看.
添加了一行,一切正常:
    // Set request body
    request.content(new StringContentProvider(JSON_HERE), "application/json");
希望它对其他人也有帮助.
| 归档时间: | 
 | 
| 查看次数: | 7588 次 | 
| 最近记录: |