隨筆 - 0, 文章 - 264, 評論 - 170, 引用 - 0

          導(dǎo)航

          <2016年7月>
          262728293012
          3456789
          10111213141516
          17181920212223
          24252627282930
          31123456

          留言簿(6)

          隨筆分類

          文章分類

          文章檔案

          AI

          android+移動開發(fā)

          apache等開源類包,工具相關(guān)

          cdn

          concurrent

          C語言

          git、svn等工具使用

          groovy、grails

          Hadoop、Storm、Spark大數(shù)據(jù)相關(guān)

          hibernate、JPA等持久化技術(shù)

          html,dom,js,css、ext、mui等前端、移動前端相關(guān)

          HTTP、HTTPS、TCP、UDP等協(xié)議相關(guān)

          IM、openfire

          Java基礎(chǔ)

          java性能優(yōu)化

          jquery

          linux相關(guān)

          lucene、solr等搜索技術(shù)相關(guān)

          maven gradle ant Jenkins自動化構(gòu)建與持續(xù)集成

          memcache

          mongodb

          nginx、squid、haproxy、varnish

          OLAP

          python、shell、perl、php

          redis

          rmi相關(guān)

          spring

          struts、webwork

          tcp/ip

          tomcat,jsp,servlet相關(guān)

          velocity等實用工具相關(guān)

          業(yè)務(wù)相關(guān)

          互聯(lián)網(wǎng)安全、過濾、網(wǎng)絡(luò)

          修煉

          其他

          區(qū)塊鏈

          壓力、性能測試相關(guān)

          地圖相關(guān)

          基礎(chǔ)

          多線程

          開發(fā)工具相關(guān)

          數(shù)據(jù)庫

          架構(gòu)

          移動互聯(lián)網(wǎng)

          設(shè)計模式

          搜索

          •  

          最新評論

          HttpClient PostMethod提交自定義參數(shù)

          用PostMethod 模擬http post請求,需要解決傳遞字符串,文件等需求。
          httpclient對此,提供了對應(yīng)實現(xiàn),實現(xiàn)方法關(guān)鍵在:RequestEntity。
          示例:
          RequestEntity requestEntity = newStringRequestEntity(text);  
          post.setRequestEntity(requestEntity); 
          示例中,是傳遞一個普通字符型參數(shù)。
          這個方法代替了以前直接設(shè)置Request body。

          RequestEntity是一個接口,有很多實現(xiàn):
          ByteArrayRequestEntity, FileRequestEntity, InputStreamRequestEntity, MultipartRequestEntity, StringRequestEntity
          基本上從名字上就可以直接看出功能,可以從字符串,流,文件,字節(jié)數(shù)組中產(chǎn)生request body。

          還有更復(fù)雜的Multipart,就是夾雜文件和普通字段的提交。
          示例如下:
          Part[] parts = {new StringPart("source""695132533"), new StringPart("status", URLEncoder.encode(status, "utf-8")), filePart};
          postMethod.setRequestEntity(
          new MultipartRequestEntity(parts, postMethod.getParams()));

          posted on 2011-01-19 13:45 小一敗涂地 閱讀(33137) 評論(6)  編輯  收藏 所屬分類: 開源工具、插件相關(guān)

          評論

          # re: HttpClient PostMethod提交自定義參數(shù)  回復(fù)  更多評論   

          謝謝。。。。對我?guī)椭艽蟆!!!!?
          2012-11-30 10:07 | amlean

          # re: HttpClient PostMethod提交自定義參數(shù)  回復(fù)  更多評論   

          萬分感謝樓主,利博亞洲www.biyingbocai.com
          2013-02-25 14:17 | 士大夫

          # re: HttpClient PostMethod提交自定義參數(shù)[未登錄]  回復(fù)  更多評論   

          很好,幫助很大,感謝
          2014-06-10 16:05 | tian

          # re: HttpClient PostMethod提交自定義參數(shù)[未登錄]  回復(fù)  更多評論   

          感謝
          2014-08-13 21:08 | 啊啊

          # re: HttpClient PostMethod提交自定義參數(shù)  回復(fù)  更多評論   

          頂頂頂
          2015-01-24 16:07 | 暗示法

          # re: HttpClient PostMethod提交自定義參數(shù)[未登錄]  回復(fù)  更多評論   

          InputStreamRequestEntity,我要把一個網(wǎng)絡(luò)文件傳到另一臺服務(wù)器,不下載到本地的話怎么實現(xiàn)呢,例如:https://www.baidu.com/img/baidu_sylogo1.gif
          用文件流上傳到騰訊微信服務(wù)器
          2016-07-29 16:37 | Kai
          主站蜘蛛池模板: 兴安县| 临桂县| 昌黎县| 江陵县| 千阳县| 延寿县| 平山县| 宜黄县| 荣昌县| 庆城县| 普洱| 大丰市| 海安县| 临安市| 门头沟区| 甘南县| 深州市| 东乌| 江孜县| 玉林市| 湘潭市| 铁力市| 乌鲁木齐县| 曲水县| 鄢陵县| 义乌市| 克山县| 金阳县| 定襄县| 清远市| 新巴尔虎右旗| 汪清县| 比如县| 阿拉善右旗| 和硕县| 奉化市| 合山市| 梁平县| 英吉沙县| 阜城县| 财经|