GET请求发送内容主体

GET请求发送内容主体

本文介绍了使用Java以HTTP GET请求发送内容主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个第三方API,该API需要在http GET请求中包含内容主体,并且不接受任何其他形式的输入.我无法对此API进行任何更改,并且所有者不接受对该API的更改请求.我知道这是一个不好的设计,但除此之外,有什么办法可以做到吗?我已经尝试过apache httpurlconnection和java url api,但是无法实现相同的目的.

I have a third party API which needs content body in a http GET request and doesn't accept any other forms of input.I cant make any changes to this API and the owners are not taking change requests to the API. I know that this is a bad design and all but is there any way this could be done ? I have tried apache httpurlconnection and java url apis, but haven't been able to achieve the same.

推荐答案

您需要使用以下内容

public class HttpGetWithBody extends HttpEntityEnclosingRequestBase {

    @Override
    public String getMethod() {
        return "GET";
    }
}

HttpGetWithBody getWithBody = new HttpGetWithBody ();
getWithBody.setEntity(y(new ByteArrayEntity(
            "<SOMEPAYLOAD FOR A GET ???>".toString().getBytes("UTF8"))););
getResponse = httpclient.execute(getWithBody );

所需的导入将是 org.apache.http.client.methods.HttpEntityEnclosingRequestBase;

这篇关于使用Java以HTTP GET请求发送内容主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-19 17:05