java - 使用 OkHTTP 客户端和 HttpsURLConnection 在 Java 中不支持获取请求方法“GET”
问题描述
因为我需要通过 post 发送数据以启动 API,但得到不受支持的错误。即使我正在使用 post 方法,请指出我在哪里做错了。我已经尝试过 OkHTTPClient 和 HTTPSURL 连接,仍然出现同样的错误
Error: **{"timestamp":"2021-03-23T06:26:43.508+0000","status":405,"error":"Method Not Allowed","message":"Request method 'GET' not supported","path":"/stsBankResponse/"}**
当我直接在浏览器中点击 URL 时,也不允许使用方法,它的有效错误但仅以编程方式使用 Post,即使相同的错误
JSONObject jsobj=new JSONObject();
jsobj.put("authmode", "Abc");
JSONArray jaarray = new JSONArray();
jaarray.put(jsobj);
JSONObject mainObj = new JSONObject();
mainObj.put("bankResponseDtl", jaarray);
String str_jsonparams = String.valueOf(mainObj);
System.out.println("PU_Auth str_jsonparams->"+str_jsonparams);
String proxyhost=common_utility.getProxyHost();
String proxyport=common_utility.getProxyPort();
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyhost, new Integer(proxyport)));
OkHttpClient client = new OkHttpClient();
OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.connectTimeout(30, TimeUnit.SECONDS);
builder.readTimeout(30, TimeUnit.SECONDS);
builder.writeTimeout(30, TimeUnit.SECONDS);
builder.proxy(proxy);
client = builder.build();
RequestBody body = RequestBody.create(JSON, str_jsonparams);
Request request = new Request.Builder()
.url(common_utility.getEmandateServerResponeURL())
.post(body)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
call.cancel();
System.out.println("ECEEEEE"+e);
}
@Override
public void onResponse(Call arg0, Response arg1) throws IOException {
}
});
解决方案
推荐阅读
- amazon-web-services - AWS ECS 部署:内存不足
- .net - ORA-08103: .net 中不再存在对象
- swift - CIstraightenFilter 为大输入返回空白图像
- java - 如何下载“com.dalsemi.onewire”包?
- spring-boot - 如何在 Spring Boot 中将带有斜杠的参数传递到存储库
- excel - 从另一个工作簿填充组合框
- ruby-on-rails - 使用原生扩展安装 mysql2 0.4.10 Gem::Ext::BuildError: ERROR: Failed to build gem native extension
- javascript - 基于数组中的数组合并数组中的javascript对象
- javascript - 导出整个 CONST js
- javascript - 如何使用javascript在firebase数据库中上传变量作为属性名称?