有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

http Java函数不起作用

我有一个小程序,可以通过http将数据插入数据库。 我做了一个函数来实现这一点,但当我在主文件中调用该函数时,它似乎不起作用。我试着调试它,但当我在行上设置断点时,它并没有显示该函数已被使用。有人能帮我吗

public class School_Planner {

/**
 * @param args the command line arguments
 */
public static  void main(String[] args) {
    // TODO code application logic here
    HTTP_Conncetion.Connect();

}   
}

public class HTTP_Conncetion {

public static void Connect(){
    try {
// open a connection to the site
URL url = new URL("http://localhost:8080/HTTP_Connection/index.php");
URLConnection con = url.openConnection();
// activate the output
con.setDoOutput(true);
PrintStream ps = new PrintStream(con.getOutputStream());
// send your parameters to your site
ps.print("firstKey=firstValue");
//ps.print("&secondKey=secondValue");

// we have to get the input stream in order to actually send the request
con.getInputStream();

// close the print stream
ps.close();
} catch (MalformedURLException e) {
    e.printStackTrace();
} catch (IOException e) {
    e.printStackTrace();
}
}
}

编辑 在Jon Skeet的指挥下,我想我必须更具体一点。我认为问题在于该函数不起作用,或者它跳过了该函数


共 (1) 个答案

  1. # 1 楼答案

    发布的代码很好,它调用了URL

    http://localhost:8080/HTTP_Connection/index.php
    

    使用参数firstKey及其值firstValue

    除非你忘了导入,这会导致编译错误。 我猜你的错误在服务器端。请仔细检查服务器

    可以肯定的是,你的问题非常不具体——没有例外,没有对你认为没有被调用的“函数”的确切描述。不是你期望发生什么,也不是你错过了什么。请调整你的问题,让你的问题有一个更具体的答案