我没有 Java 经验,我得到了一些 XML 交互的工作示例代码,我唯一的问题是我需要 POST 数据(用户名/密码)
相关代码为:
static String myUrlString = "http://www.grupoandroid.com/interface/mobile/index.php";
protected TheParser(){
try {
this.myUrl = new URL(myUrlString);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
protected InputStream getInputStream() {
try {
return myUrl.openConnection().getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
最佳答案
您可以使用HttpURLConnection
protected InputStream getInputStream() {
try {
HttpURLConnection con = new HttpURLConnection(myUrl);
con.setRequestMethod("POST");
//writeout data to the output stream
return con.getInputStream();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
关于java - 将 java 示例从 GET 转换为 POST,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5931443/