我有以下代码。
String name = "hello";
String pass = "testing";
String des = "this is info";
String u = "http://mysite.com/insertinfo.php?name=" + name + "&pass=" + pass + "&description=" + des;
URL url = new URL(u);
url.openConnection();
由于某种原因,它没有在网站上运行PHP脚本,我不知道什么是错的,请帮忙!
我知道脚本运行正常,如果我把它放在我的webbrowser中它插入信息很好,但它不是用Java。
答案 0 :(得分:1)
openConnection()
实际上并没有加载页面。你需要获得从那里返回的UrlConnection
对象,然后是connect()
和getContent()
(也许你不需要getContent()
,先试试吧)
e.g。
String name = "hello";
String pass = "testing";
String des = "this is info";
String u = "http://mysite.com/insertinfo.php?name=" + name + "&pass=" + pass + "&description=" + des;
URL url = new URL(u);
UrlConnection conn = url.openConnection();
conn.connect();
conn.getContent();
此处有更多信息:http://docs.oracle.com/javase/6/docs/api/java/net/URLConnection.html