duanqi5333 2015-03-26 18:35
浏览 61
已采纳

填写网站中的PHP / HTML字段

I want to automatically fill the field called "email" of a webpage thesite.com/email.php, which code is something similar to this:

<input type="text" name="email" value="" size="24">
<br> <input type="submit" name="submit" value="Send">

And then, after filling the field, I also would like to perform the action "submit". But I don't know actually how to do that with Java Can someone help me? Thanks a lot.

  • 写回答

2条回答 默认 最新

  • douye1940 2015-03-26 18:51
    关注

    To programmatically submit the form with java, you don't directly fill the form, rather send the form information to the submit page via HTTP GET or POST. You did not provide the onsubmit value in your post, but you would use that webpage URL and send the form information via a URLConnection. If using GET, you send the data in a query string (where key/value are the form parameters):

    URL url = new URL("http://mywebsite/form-submit-webpage.php?key1=value1&key2=value2");
    

    If POST, you must use the OutputStream of URL connection to set the POST key/value pairs

    URL url = new URL("http://mywebsite/form-submit-webpage.php");
    URLConnection conn = url.openConnection();
    conn.setDoOutput(true);
    OutputStream os = conn.getOutputStream();
    //write key value pairs to os. 
    

    From their, get get the InputStream from the URLConnection to read the results. See https://docs.oracle.com/javase/tutorial/networking/urls/readingURL.html

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿