无法通过JAVA在w REST API上执行修补程序

无法通过JAVA在w REST API上执行修补程序,java,rest,api,patch,Java,Rest,Api,Patch,我想用不同的方法调用API: 使用HttpClient可以进行post和get操作 我不能做补丁和删除方法,有人实现了这样的事情吗?怎么做 后处理方法1 public static String sendPost(String requestURL, Map<String, String> headers, String postParameters, boolean withProxy) throws IOException { HttpURLConnec

我想用不同的方法调用API:

使用HttpClient可以进行post和get操作

我不能做补丁和删除方法,有人实现了这样的事情吗?怎么做

后处理方法1

public static String sendPost(String requestURL, Map<String, String> headers, String postParameters,
        boolean withProxy) throws IOException {

    HttpURLConnection con = createProxyHttpConnection(requestURL, withProxy);
    con.setRequestMethod("POST");
    con.setDoOutput(true);

    for (Map.Entry<String, String> entry : headers.entrySet()) {
        con.setRequestProperty(entry.getKey(), entry.getValue());

    }
    DataOutputStream wr = new DataOutputStream(con.getOutputStream());
    wr.writeBytes(postParameters);
    String response = IOUtils.toString(con.getInputStream(), "UTF-8");

    wr.close();
    con.disconnect();
    return response;

}

在不提供任何代码的情况下,我的最佳猜测是,您试图发出这些修补程序和删除请求的网络已经阻止了这些HTTP谓词,因此您无法发出它们。大多数网络安全工具认为除了GET和POST以外的任何动词都是不安全的,因此黑名单他们

< P>解决:

更改
HttpPost请求=新的HttpPost(requestURL)通过
HttpPatch请求=新的HttpPatch(requestURL)


我的url(https)也有问题,所以谢谢@Ivan Jadric

你使用了框架吗?发布你的代码后,我会编辑我的代码,不,我没有使用框架(这是一个appium应用程序,我绕过了一个无法在移动设备上实现自动化的步骤) @SamuelRobert@SamuelRobert:code adde:)您必须在服务器端启用PATCH方法来执行补丁请求…感谢您的回答,事实上通过SoapUI我可以执行PUT、DELETE和PATCH,我面临的问题是通过java,我只是添加了代码根据错误消息判断,这不是java本身的错误,但看起来更像是404错误。添加一些日志以查看发出请求的完整路径,如果URL干净且良好,则服务器可能没有该资源的POST、补丁映射
public static HttpResponse sendPostBis(String requestURL, Map<String, String> headers, String payload,
        boolean withProxy) throws IOException {

    StringEntity sEntity = new StringEntity(payload,
            ContentType.APPLICATION_FORM_URLENCODED);

    HttpClient httpClient = HttpClientBuilder.create().build();
    HttpPost request = new HttpPost(requestURL);
    for (Map.Entry<String, String> entry : headers.entrySet()) {
        request.addHeader(entry.getKey(), entry.getValue());

    }
    request.setEntity(sEntity);

    HttpResponse response = httpClient.execute(request);
    return response;

}
{"error":"No route found for \u0022POST \RESOURCE","message":"No route found for \u0022POST RESOURCE"}