commons-httpclient-2.0在setParameter的时候容易顺序弄错

类别:Java 点击:0 评论:0 推荐:
        postMethod.setParameter("localKBURL", getLocalKBURL());
        postMethod.setRequestBody(bin);
       
       
        postMethod.addRequestHeader("Content-type",
            "text/xml; charset=ISO-8859-1");

setParameter在setRequestBody之前,应该后者会clear parameters。
虽然按照上面的顺序应该是没有问题的,但是实际上setParameter和setHeader存在冲突,只能把参数加入Header:
        postMethod.addRequestHeader("localKBURL",getLocalKBURL());

然后,再取参数时:
 String localKBURL = request.getParameter("localKBURL");
 if(localKBURL == null || localKBURL.length() == 0)
  localKBURL = request.getHeader("localKBURL");

本文地址:http://com.8s8s.com/it/it14603.htm