我有一个Android应用程序,正在尝试使用HttpUrlConnection向我的服务器发出GET请求。当我在单独的测试桌面应用程序中测试代码时,一切正常。然而,当我在我的Android设备上运行它时,我的服务器注册了一个POST请求,而不是GET。
以下是我的get
方法的代码:
public static String get(String url) throws IOException {
HttpURLConnection conn = connFromUrlString(url);
conn.setRequestMethod("GET");
conn.setDoInput(true);
conn.setDoOutput(true);
conn.connect();
String out = IOUtils.toString(conn.getInputStream(), "UTF-8");
conn.disconnect();
return out;
}