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

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

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

    sunfruit[請訪問http://www.fruitres.cn]

    --我相信JAVA能走得更遠 QQ:316228067

    [JAVA]使用HttpURLConnection進行POST方式提交

    --sunfruit

    用HttpURLConnection進行Post方式提交,下面給出一個例子

        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 的,而是用來設置請求的頭信息,比如:
           setRequestProperty("Content-type","text/html");
           setRequestProperty("Connection",   "close");
           setRequestProperty("Content-Length",xxx);

    當然如果不設置的話,可以走默認值,上面的例子中就沒有進行相關設置,但是也可以正確執行

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

    評論

    # re: [JAVA]使用HttpURLConnection進行POST方式提交 2006-07-31 16:55 南柯一夢

    我對你的崇拜不是一句兩句能說清??!  回復  更多評論   

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

    呵呵,不敢當,相互學習吧  回復  更多評論   

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

    崇拜ing.....

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

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

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

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

    非常感謝~~!  回復  更多評論   

    # re: [JAVA]使用HttpURLConnection進行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());  回復  更多評論   

    # re: [JAVA]使用HttpURLConnection進行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方法登入服務器,然后該怎么做?我想拿到登入后的下個頁面該怎么寫代碼?請指教!謝謝
      回復  更多評論   

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

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

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

    很好的例子,3q  回復  更多評論   

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

    aaaaaaaaaaaaaaaaaaaaaaaa  回復  更多評論   

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

    很好!謝謝!  回復  更多評論   

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

    我提交過去的中文是亂碼,怎么解決?轉碼都不行  回復  更多評論   

    主站蜘蛛池模板: 无码人妻一区二区三区免费看 | 亚洲精品~无码抽插| 亚洲色偷偷色噜噜狠狠99网| 最近中文字幕电影大全免费版 | 亚洲国产美女精品久久| 98精品全国免费观看视频| 亚洲精品无码AV人在线播放| xxxxx做受大片视频免费| 亚洲一区二区三区免费| 一级做a爱片特黄在线观看免费看| 国产免费观看黄AV片| 美女被爆羞羞网站免费| 亚洲国产精品13p| 曰韩无码AV片免费播放不卡| 国产精品亚洲高清一区二区| 2022国内精品免费福利视频| 77777亚洲午夜久久多人| 日韩免费高清播放器| 亚洲高清在线视频| 久久久精品2019免费观看 | 一级中文字幕乱码免费| 中文字幕在亚洲第一在线| 国产情侣久久久久aⅴ免费| 久久丫精品国产亚洲av| 4虎永免费最新永久免费地址| 亚洲妇女熟BBW| 免费观看国产精品| gogo免费在线观看| 亚洲视频免费观看| 成年在线网站免费观看无广告| 国产亚洲福利精品一区二区| 国产亚洲精久久久久久无码AV| 久久青草免费91线频观看站街| 亚洲国产精品免费在线观看| 日韩免费三级电影| 中文字幕一区二区三区免费视频| 久久亚洲AV成人无码| 免费高清小黄站在线观看 | 国产精品久久亚洲一区二区| 亚洲精品中文字幕无码蜜桃| **一级毛片免费完整视|