小编Mik*_*ome的帖子

你如何在Java中执行http帖子?

这是我正在使用的代码.它不是将数据发布到页面,而是像常规文本文件一样下载它.所以,我实际上是返回了html代码并且没有提交表单.

我知道html表单有效.如果我在浏览器中打开它,我可以发布到它,我的数据显示在我的数据库中.我猜我错过了参数或其他东西.

public void testComm ()
{
try
    {
    URL         url;
    URLConnection   urlConn;
    DataOutputStream    printout;
    DataInputStream input;

    url = new URL ("http://mysite.com/myform.html");

    // URL connection channel.
    urlConn = url.openConnection();

    // Let the run-time system (RTS) know that we want input.
    urlConn.setDoInput (true);

    // Let the RTS know that we want to do output.
    urlConn.setDoOutput (true);

    // No caching, we want the real thing.
    urlConn.setUseCaches (false);

    // Specify the content type.
    urlConn.setRequestProperty
    ("Content-Type", "application/x-www-form-urlencoded");

    // Send POST output.
    printout = new …
Run Code Online (Sandbox Code Playgroud)

java post http

2
推荐指数
1
解决办法
3793
查看次数

标签 统计

http ×1

java ×1

post ×1