Java 使用HTTPUrlConnection发布
我正在使用HttpUrlConnection连接一个web服务,其中我有一个表单和一个按钮 源代码中的部分是:Java 使用HTTPUrlConnection发布,java,Java,我正在使用HttpUrlConnection连接一个web服务,其中我有一个表单和一个按钮 源代码中的部分是: <form action="main.php4?page=markt3art=UIN=484504321483db0fc35d1e8e660b99c8&x=&y=filled=1" method="POST"> <input type="hidden" value="" name="p"></input>
<form action="main.php4?page=markt3art=UIN=484504321483db0fc35d1e8e660b99c8&x=&y=filled=1" method="POST">
<input type="hidden" value="" name="p"></input>
<input type="hidden" value="1755219" name="buy2f8d0"></input>
<input type="hidden" value="1755219" name="buy"></input>
<input type="text" value="323" size="9" maxlength="16" name="teilkauf"></input>
<img width="1" hspace="20" height="1" src="pics/leer.gif"></img>
<input class="send" type="submit" value=" buy "></input>
</form>
但它不起作用。有什么帮助吗?谢谢。您必须对表单的操作发出POST请求,而不是表单所在的站点 表单就像后端服务器的前端,当您单击“提交浏览器”时,它会向操作生成一个请求
因此,我不需要在表单的位置上发布main.php4?page=markt3art=UIN=484504321483db0fc35d1e8e660b99c8&x=&y=filled=1我只需要通过http://...main.php4?page=markt3art=UIN=484504321483db0fc35d1e8e660b99c8&x=&y=filled=1? 因为它不起作用。(对不起,我说的是英语)。您可能需要在每次发布该数据时获取该UIN令牌。
URL url = new URL(www);
HttpURLConnection conexion = (HttpURLConnection)url.openConnection();
String forSending = "1";
String charset = "UTF-8";
String stringToSend = URLEncoder.encode(forSending, charset);
conexion.setDoOutput(true);
conexion.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(
conexion.getOutputStream());
out.write("teilkauf=" + stringToSend);
out.flush();
out.close();