0

I have the following code.

    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();

for some reason it isn't running the php script on the site and I don't know what's wrong, please help!

I know that the script runs properly, if I put it in my webbrowser it inserts info fine, but it doesn't in Java.

2
  • you spelt insert wrong if that matters Commented Mar 22, 2013 at 22:10
  • it doesn't / and I just corrected that Commented Mar 22, 2013 at 22:12

1 Answer 1

1

openConnection() doesn't actually load the page. You need to get the UrlConnection object that is returned from that, then connect() and getContent() (maybe you don't need the getContent(), try it without first)

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();

more info here: http://docs.oracle.com/javase/6/docs/api/java/net/URLConnection.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.