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

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

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

    posts - 23,comments - 66,trackbacks - 0
    from:http://blog.csdn.net/ambitiontan/archive/2006/01/05/571272.aspx

    服務器:
    1.jsp
    <body>
    <form name="_ctl0" method="post" action="TestFileManager.aspx" id="_ctl0" enctype="multipart/form-data">
    <input type="hidden" name="__VIEWSTATE" value="dDwyNTIzNjA5NDU7Oz7rsE3eBYzQHDVtl+aTn96MvQW6PQ==" />
    <p>
    <input name="uploadfile1" id="uploadfile1" type="file" size="49" />
    <input type="submit" name="Button1" value="?" id="Button1" />
    </p>
    <p>
    <span id="Label1" style="width:459px;"></span>
    </p>
    <!-- Insert content here -->
    </form>
    </body>
    客戶端:
    首先創建一個到服務器http的請求
    HttpRequest request = new HttpRequest("http://服務器/1.jsp");
    第一次使用的是GET方式
    request.setMethod("GET");
    緊接著進行一些請求的屬性設置
    request.setRequestHeader("Cache-Control", "no-cache");
    這里保持連接,因為后面還要發送數據到服務器呢
    request.setRequestHeader("Connection", "Keep-Alive");
    下面是一些無關緊要的屬性設置了。
    request.setRequestHeader("Accept", "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*");
    request.setRequestHeader("Accept-Encoding", "gzip, deflate");
    request.setRequestHeader("Accept-Language", "en-au");
    request.setRequestHeader("Referer", "http://服務器/1.jsp");
    request.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3215; .NET CLR 1.0.3705)");
    構造好了連接請求,然后連接
    request.connect();
    緊接著提取Cookie值,在后文的post中可以用到。
    String strCookie = request.getResponseHeader("Set-Cookie");
    strCookie = strCookie.substring(0,strCookie.indexOf(";"));
    下面通過循環查找,提取__VIEWSTATE的值
    for ( int i = 0; i < nlist.getLength(); i++) {
    node = nlist.item(i);
    strName = getNodeAttributeValue(node,"name");
    if ( strName.equals("__VIEWSTATE") ) {
    strValue = getNodeAttributeValue(node,"value");
    break;
    }
    }
    往服務器組織發送數據
    DataOutputStream dos = new DataOutputStream(request.getOutputStream());
    dos.writeBytes("-----------------------------"+strBoundary);//這是每個要被發送數據間的間隔
    dos.writeBytes(" Content-Disposition: form-data; name="__VIEWSTATE"");
    dos.writeBytes(" "+strValue);
    dos.writeBytes(" -----------------------------"+strBoundary);
    這里面是發送文件的部分
    dos.writeBytes(" Content-Disposition: form-data; name="uploadfile1"; filename="" + strFileName + """);
    dos.writeBytes(" Content-Type: text/xml");
    dos.writeBytes(" ");
    dos.writeBytes(new String(data));
    dos.writeBytes(" -----------------------------"+strBoundary);
    dos.writeBytes(" Content-Disposition: form-data; name="Button1"");
    dos.writeBytes(" 上傳");
    dos.writeBytes(" -----------------------------"+strBoundary+"--");
    dos.writeBytes(" ");
    dos.close();
    posted on 2006-03-21 21:44 rd2pm 閱讀(2263) 評論(1)  編輯  收藏

    FeedBack:
    # re: 用JAVA模擬POST發送數據
    2006-12-20 09:36 | 王建平
    你的HttpRequest 在那個包里面?
      回復  更多評論
      

    只有注冊用戶登錄后才能發表評論。


    網站導航:
     

    主站蜘蛛池模板: 亚洲欧美乱色情图片| 亚洲国产成人a精品不卡在线| 中文字幕无线码中文字幕免费| 免费无毒a网站在线观看| 好吊妞788免费视频播放| 亚洲情A成黄在线观看动漫软件| 真人无码作爱免费视频| 国产一级淫片a免费播放口之| 亚洲中文字幕无码一区二区三区| 亚洲AV福利天堂一区二区三| 国产免费一区二区视频| 亚洲av无码国产精品色午夜字幕| 亚洲日本中文字幕天天更新| 在线jlzzjlzz免费播放| 狠狠色伊人亚洲综合网站色 | 国产精品亚洲av色欲三区| 卡1卡2卡3卡4卡5免费视频| 亚洲AV无码成人精品区狼人影院| a级毛片免费全部播放| 亚洲av综合色区| 亚洲视频免费在线看| 国产精品久久亚洲不卡动漫| 免费久久精品国产片香蕉| a级毛片100部免费观看| 亚洲人成在线中文字幕| 亚洲成A人片在线观看无码3D| 国产成人精品日本亚洲专| 毛片A级毛片免费播放| 免费大片av手机看片| 亚洲va无码va在线va天堂| 亚洲三级高清免费| 色婷婷综合缴情综免费观看| 亚洲成人免费在线| 在线观看免费大黄网站| 青青操视频在线免费观看| 亚洲国产av美女网站| 亚洲人成无码网站久久99热国产| 久久无码av亚洲精品色午夜| 亚洲中文字幕伊人久久无码| 日本视频免费高清一本18| 中文日韩亚洲欧美制服|