将 java 示例从 GET 转换为 POST
我在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);
}
}
im not experienced in java and i got a working example code for some XML interaction, my only problem is that i need to POST data (username/password)
the relevant code is:
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 HttpURLConnection
you can use HttpURLConnection
我认为你最好使用 http 客户端库,而不是自己解析完整的 http 堆栈。
apache-http-client
hotpotato
您可以在网络上找到足够的示例和教程。
I think you're better off using an http-client library, rather than parsing the full http stack yourself.
apache-http-client
hotpotato
You can find enough examples and tutorials in the web for these.