如何用java发送post表单?
我想在网站上用java发送帖子表格。我想出了这个,但我不知道下一步该做什么,也不知道这是否是正确的方法。
URL url = new URL("http://127.0.0.1");
URLConnection conn=url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
帖子表格看起来像这样。
<form action="prikaz4.php" method="post">
<select name="igralec"/>
<option value="Kobe Bryant">Kobe Bryant</option>
<option value="Dwayne Wade">Dwayne Wade</option>
<input type="submit" />
</form>
I would like to send a post form with java on a website. I came up with this, but I dont what to do next or if this is even the right way.
URL url = new URL("http://127.0.0.1");
URLConnection conn=url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
the post form looks like this.
<form action="prikaz4.php" method="post">
<select name="igralec"/>
<option value="Kobe Bryant">Kobe Bryant</option>
<option value="Dwayne Wade">Dwayne Wade</option>
<input type="submit" />
</form>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以编写与此类似的代码:
You can write code similar to this :
Apache 的 HttpClient 项目将为您更好地处理这个问题。
或者你可以尝试这个代码:
Apache's HttpClient project will handle this better for you.
or you can try this code:
您可能需要考虑使用 Apache 的 HttpClient 库。它有 HttpPost 类,非常易于使用。
You may want to consider using HttpClient library from Apache. It's got
HttpPost
class, which is very easy to use.使用 unirest 很容易。
It's easy to use unirest .