Android 连接未更改 headers/request 方法
Android Connection not changing headers/request method
给定以下代码:
private HttpsURLConnection buildConnection(final String urlString) throws MalformedURLException,
IOException, ProtocolException {
final URL url = new URL(urlString);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
return connection;
}
为什么 connection.method = "GET"?似乎也忽略了对 addRequestProperty 的任何调用。
这是在 Windows 上使用 Android、Android Studio 编写代码(因此使用 类 它通过 Android SDK 下载的任何内容, 这应该和其他人一样...)
我发现我的问题是调试 windows 由于某种原因没有更新。代码正在更改内存中的变量,但 Android Studio 和 Eclipse 中的调试 windows 无法反映正确的信息。
我的问题最终源于使用大写 I 而不是小写 I 的授权 header,导致未授权被返回,并且调试信息未反映正确信息最终弄乱了我认为错误的地方,并且把我带到了一个兔子洞里两天。
给定以下代码:
private HttpsURLConnection buildConnection(final String urlString) throws MalformedURLException,
IOException, ProtocolException {
final URL url = new URL(urlString);
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
connection.setChunkedStreamingMode(0);
return connection;
}
为什么 connection.method = "GET"?似乎也忽略了对 addRequestProperty 的任何调用。
这是在 Windows 上使用 Android、Android Studio 编写代码(因此使用 类 它通过 Android SDK 下载的任何内容, 这应该和其他人一样...)
我发现我的问题是调试 windows 由于某种原因没有更新。代码正在更改内存中的变量,但 Android Studio 和 Eclipse 中的调试 windows 无法反映正确的信息。
我的问题最终源于使用大写 I 而不是小写 I 的授权 header,导致未授权被返回,并且调试信息未反映正确信息最终弄乱了我认为错误的地方,并且把我带到了一个兔子洞里两天。