本文介绍了java HttpURLConnection.setRequestMethod()不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将请求方法从GET更改为POST.这是我的代码:
i want to change the request methodo from GET to POST. This is my code:
HttpURLConnection connection = null;
URL url = new URL("https://accounts.google.com/o/oauth2/token");
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
但是如您在此图中看到的,在调试请求的方法时,它没有改变:
But as u see in this image while debugging the methodo of the request doesn't change:
推荐答案
那只是一个. HttpsURLConnectionImpl
对象具有对委托的引用,并设置了委托的request方法.如果展开 delegate
字段并检查其 method
字段,则会看到 POST
.
That's just an implementation detail. The HttpsURLConnectionImpl
object has a reference to a delegate, and sets that delegate's request method. If you expand the delegate
field and check its method
field, you'll see POST
.
如果继续执行代码,您还将看到它尝试发送POST请求.
If you follow through with the code, you'll also see it attempts to send a POST request.
这篇关于java HttpURLConnection.setRequestMethod()不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!