<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    sunfruit[請(qǐng)?jiān)L問http://www.fruitres.cn]

    --我相信JAVA能走得更遠(yuǎn) QQ:316228067

    [JAVA]使用HttpURLConnection進(jìn)行POST方式提交

    --sunfruit

    用HttpURLConnection進(jìn)行Post方式提交,下面給出一個(gè)例子

        URL url = null;
        HttpURLConnection httpurlconnection = null;
        try
        {
          url = new URL("http://xxxx");

          httpurlconnection = (HttpURLConnection) url.openConnection();
          httpurlconnection.setDoOutput(true);
          httpurlconnection.setRequestMethod("POST");
          String username="username=02000001";
          httpurlconnection.getOutputStream().write(username.getBytes());
          httpurlconnection.getOutputStream().flush();
          httpurlconnection.getOutputStream().close();
          int code = httpurlconnection.getResponseCode();
          System.out.println("code   " + code);

        }
        catch(Exception e)
        {
          e.printStackTrace();
        }
        finally
        {
          if(httpurlconnection!=null)
            httpurlconnection.disconnect();
        }

    其中HttpURLConnection中的addRequestProperty方法,并不是用來添加Parameter 的,而是用來設(shè)置請(qǐng)求的頭信息,比如:
           setRequestProperty("Content-type","text/html");
           setRequestProperty("Connection",   "close");
           setRequestProperty("Content-Length",xxx);

    當(dāng)然如果不設(shè)置的話,可以走默認(rèn)值,上面的例子中就沒有進(jìn)行相關(guān)設(shè)置,但是也可以正確執(zhí)行

    posted on 2006-03-13 15:47 sunfruit 閱讀(38051) 評(píng)論(12)  編輯  收藏 所屬分類: JAVA SE & EE

    評(píng)論

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2006-07-31 16:55 南柯一夢(mèng)

    我對(duì)你的崇拜不是一句兩句能說清!!  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2006-08-01 14:57 sun fruit

    呵呵,不敢當(dāng),相互學(xué)習(xí)吧  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交[未登錄] 2007-07-11 17:04 sun

    崇拜ing.....

    還有個(gè)問題要請(qǐng)教
    在httpurlconnection.setRequestMethod("POST");下邊加上
    了httpurlconnection.setRequestProperty("Content-type", "text/html");
    為什么就不行了?得不到參數(shù)值  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2007-07-11 20:53 fruit

    加上httpurlconnection.setRequestProperty("Content-type", "text/html"); ,表明提交的類型是text/html,這個(gè)只能通過數(shù)據(jù)流獲得  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2007-07-24 18:26 anosn

    非常感謝~~!  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交不成功 2008-03-26 17:25 肖圣春

    public class PostDemo {
    private static String FILE_NAME = SubmitMMSMsg.dir + ".zip";
    static URL url = null;
    static HttpURLConnection httpurlconnection = null;
    public static void doPost(){
    try
    {
    url = new URL("http://mpublish.maxtong.com/interface.php");

    httpurlconnection = (HttpURLConnection) url.openConnection();
    httpurlconnection.setDoOutput(true);
    httpurlconnection.setRequestMethod("POST");
    // String name ="zip_name=";
    // File f = new File("d:\\1.txt");
    // FileOutputStream is = new FileOutputStream(f);
    // BufferedOutputStream bos = new BufferedOutputStream(is);
    // bos.write(getFileString().getBytes());
    httpurlconnection.getOutputStream().write(getFileString().getBytes());
    httpurlconnection.getOutputStream().flush();
    httpurlconnection.getOutputStream().close();
    int code = httpurlconnection.getResponseCode();
    System.out.println("code " + code);
    System.out.println(httpurlconnection.getResponseMessage());  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2008-06-03 16:09 dengqianyong

    httpurlconnection.getOutputStream().write(username.getBytes());
    httpurlconnection.getOutputStream().write("&".getBytes());
    httpurlconnection.getOutputStream().write(password.getBytes());
    httpurlconnection.getOutputStream().flush();
    httpurlconnection.getOutputStream().close();

    比如這段代碼是通過post方法登入服務(wù)器,然后該怎么做?我想拿到登入后的下個(gè)頁面該怎么寫代碼?請(qǐng)指教!謝謝
      回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2008-08-26 11:52 張麗云

    大俠:
    如果我要跨域上傳文件應(yīng)該怎么辦呢,望多多指教。qq:379878654 回復(fù)郵箱也可以,謝謝了  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2011-11-11 11:37 1111111111

    很好的例子,3q  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交[未登錄] 2012-07-21 21:18 aaa

    aaaaaaaaaaaaaaaaaaaaaaaa  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2013-04-19 20:52 嵐剎

    很好!謝謝!  回復(fù)  更多評(píng)論   

    # re: [JAVA]使用HttpURLConnection進(jìn)行POST方式提交 2013-09-17 11:12 溫云

    我提交過去的中文是亂碼,怎么解決?轉(zhuǎn)碼都不行  回復(fù)  更多評(píng)論   

    主站蜘蛛池模板: 亚洲理论在线观看| 亚洲av无码成人精品国产 | 最近免费中文在线视频| 久久精品国产亚洲av麻豆蜜芽 | 亚洲大尺度无码无码专区| 国产成人精品免费视频动漫| 看全免费的一级毛片| 亚洲AV中文无码乱人伦下载| 成人免费淫片在线费观看| 一级有奶水毛片免费看| 亚洲va成无码人在线观看| 在线观看亚洲精品国产| 桃子视频在线观看高清免费完整| 永久免费无码网站在线观看个| 亚洲成a人片77777群色| 亚洲综合久久夜AV | 999国内精品永久免费视频| 国产精品玖玖美女张开腿让男人桶爽免费看 | CAOPORN国产精品免费视频| 亚洲自偷自偷在线成人网站传媒 | 无码欧精品亚洲日韩一区| 国产成人啪精品视频免费网| 99re6在线视频精品免费下载| 日韩电影免费在线观看网址| 亚洲制服丝袜第一页| 亚洲毛片αv无线播放一区| 在线视频免费观看www动漫| 免费国产黄网站在线观看| 免费无码国产V片在线观看| 亚洲综合一区二区三区四区五区| 亚洲成在人天堂在线| 国产精品亚洲产品一区二区三区 | 天天天欲色欲色WWW免费| 久久99国产综合精品免费| 久久不见久久见免费影院www日本| 亚洲精品宾馆在线精品酒店| 亚洲国产品综合人成综合网站| 亚洲av无码国产精品夜色午夜 | 黄页网址在线免费观看| 亚洲欧美日韩国产成人| 亚洲国产精品久久久久秋霞影院|