怎么把postmethod 添加参数里面的参数打出来

求:HttpClient.executeMethod(PostMethod)返回值详解_百度知道
色情、暴力
我们会通过消息、邮箱等方式尽快将举报结果通知您。
求:HttpClient.executeMethod(PostMethod)返回值详解
.....:具体表示什么500....过多的解释就不需要了:又是什么等等.:表示成功400....,就要下面的返回值表示什么东东! 200
我有更好的答案
com/view/1790469.htm 参考这里://baike.htm" target="_blank">http<a href="/view/1790469.baidu
采纳率:31%
为您推荐:
其他类似问题
httpclient的相关知识
等待您来回答博客分类:
HTTPClient PostMethod 中文乱码问题解决方案(2种)
http://blog.csdn.net/apei830/article/details/5526236
Apache HttpClient ( http://jakarta.apache.org/commons/httpclient/ ) 是一个纯 Java 的HTTP 协议的客户端编程工具包, 对 HTTP 协议的支持相当全面, 更多细节也可以参考IBM 网站上的这篇文章 HttpClient入门 (/developerworks/cn/opensource/os-httpclient/ ).
不过在实际使用中, 还是发现按照最基本的方式调用 HttpClient 时, 并不支持 UTF-8 编码。
现在给出2个解决方案:
一、在调用PostMethod方法时设置字符编码:
view plaincopy to clipboardprint?
PostMethod postMethod = new PostMethod(&
&&&&&&& "http://127.0.0.1:8080/HttpClientServer/login.do");&
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");&
PostMethod postMethod = new PostMethod(
"http://127.0.0.1:8080/HttpClientServer/login.do");
postMethod.getParams().setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET,"utf-8");
二、重载PostMethod的getRequestCharSet()方法, 返回我们需要的编码(字符集)名称, 就可以解决 UTF-8 或者其它非默认编码提交 POST 请求时的乱码问题了.
view plaincopy to clipboardprint?
//Inner class for UTF-8 support&&&&&
&& public static class UTF8PostMethod extends PostMethod{&&&&
&&&&&& public UTF8PostMethod(String url){&&&&
&&&&&&&&&& super(url);&&&&
&&&&&& }&&&&
&&&&&& @Override&&&
&&&&&& public String getRequestCharSet() {&&&&
&&&&&&&&&& //return super.getRequestCharSet();&&&&&
&&&&&&&&&& return "utf-8";&&&&
&&&&&& }&&&&
&& }&&&&&&
//Inner class for UTF-8 support&&
&&& public static class UTF8PostMethod extends PostMethod{&&
&&&&&&& public UTF8PostMethod(String url){&&
&&&&&&&&&&& super(url);&&
&&&&&&& }&&
&&&&&&& @Override&
&&&&&&& public String getRequestCharSet() {&&
&&&&&&&&&&& //return super.getRequestCharSet();&&
&&&&&&&&&&& return "utf-8";&&
&&&&&&& }&&
&&& }&&&&&
view plaincopy to clipboardprint?
PostMethod postMethod = new UTF8PostMethod(&
&&&&&&&&&&&&&&& "http://127.0.0.1:8080/HttpClientServer/login.do");&
PostMethod postMethod = new UTF8PostMethod(
"http://127.0.0.1:8080/HttpClientServer/login.do");
三、最后服务器端要配合客户端,设置下编码字符集:
view plaincopy to clipboardprint?
public void doPost(HttpServletRequest request, HttpServletResponse response)&
&&&&&&& throws ServletException, IOException {&
&&& //解决中文乱码问题,此步不可少&&
&&& request.setCharacterEncoding("UTF-8");&
&&& response.setContentType("text/html");&
&&& response.setCharacterEncoding("UTF-8");&
&&& PrintWriter out = response.getWriter();&
&&& String username = (String) request.getParameter("username");&
&&& String password = (String) request.getParameter("password");&
&&& System.out.println("******************** doPost被执行了 ********************");&
&&& System.out.println("您的请求参数为:/tusername:" + username + "/tpassword:"&
&&&&&&&&&&& + password);&
&&& out.print("您的请求参数为:/tusername:" + username + "/tpassword:" + password);&
&&& out.flush();&
&&& out.close();&
浏览: 29602 次
来自: 武汉
/blog/ ...
http://www.oschina.net/p/hudson ...
持续集成引擎 Hudson
已经有这样的产品了:bamboo
实现了请分享一下哦HttpClient使用Post和Get提交参数;;importjava.io.IOExceptio;importjava.net.URLEncode;mons;mons;mons;importorg.apach
tpClient使用Post和Get提交参数
import java.io.IOE
import java.net.URLE
import mons.client.C
import mons.client.M
import mons.client.NameValueP
import mons.client.methods.GetM
import mons.client.methods.PostM
public class ClientTest {
public static void main(String[] args) throws Exception{
String url = &/webservices/DomesticAirline.asmx/getDomesticAirlinesTime&;
String host = &..cn&;
String param = &startCity=&+URLEncoder.encode(&杭州&, &utf-8&)+&&lastCity=&theDate=&userID=&;
Client Client = new Client();
Client.getHostConfiguration().setHost(host, 80, &&);
Method method = getMethod(url, param);
//Method method = postMethod(url);
Client.executeMethod(method);
String response = method.getResponseBodyAsString();
//String response = new
String(method.getResponseBodyAsString().getBytes(&ISO-8859-1&));
System.out.println(response);
private static Method getMethod(String url,String param) throws IOException{
GetMethod get = new GetMethod(url+&?&+param);
get.releaseConnection();
private static Method postMethod(String url) throws IOException{
PostMethod post = new PostMethod(url);
post.setRequestHeader(&Content-Type&,&application/x--form-charset=gbk&);
NameValuePair[] param = { new NameValuePair(&startCity&,&杭州&),
new NameValuePair(&lastCity&,&沈阳&),
new NameValuePair(&userID&,&&),
new NameValuePair(&theDate&,&&) } ;
post.setRequestBody(param);
post.releaseConnection();
如果PostMethod提交的是中文字符,需要加上相应的编码格式:
post.setRequestHeader(&Content-Type&,&application/x--form-charset=gbk&);
如果GetMethod提交的参数有中文字符,需要先转换成utf-8格式:
URLEncoder.encode(&杭州&, &utf-8&);
三亿文库包含各类专业文献、高等教育、中学教育、幼儿教育、小学教育、行业资料、生活休闲娱乐、各类资格考试、Ht
tpClient使用Post和Get提交参数94等内容。 
 以GET或者POST方式向网页提交参数_计算机软件及应用_IT/计算机_专业资料。html get...HttpMethod method = getPostMethod();//使用 POST 方式提交数据 client.execut...  java发送ht tp的get、post请求===_计算机软件及应用_IT/计算机_专业资料。java...@param param * 请求参数,请求参数应该是 name1=value1&name2=value2 的形式...  最后用 HttpPost 对象把集合存入请求体中。 用 HttpClient 实现 GET 提交: 复制代码 public void load(View view){ final String qq = et_qq.getText()....  get 是从服务器上获取数据,post 是向服务器传送数据。 2. get 是把参数数据队列加到提交表单的 ACTION 属性所指的 URL 中,值和表单内各个字段 一一对应,在 ...  对于 get 方法来说,都是把数据串联在请求的 url 后面作为参数,如: http://...客户端(浏览器)的 form 表单用 post 方法是如何将数据编码后提交给服务 器端...  浅谈get 和 post 提交方法的不同 Http 定义了与服务器交互的不同方法,最基本...3.在 ASP 中,服务端获取 GET 请求参数用 Request.QueryString,获取 POST 请求...  表单的提交方式 POST 和 GET 有什么区别作者:闪吧 类型:原创 来源:闪吧 表单...本例中用到的表单的属性解释(ASP 部分请参考第四部分): Get 把参数添加到 ...  如何用get方post方式向http接口发送数据_计算机软件及...(&http call failed,参数 param1不能为空,程序...4 import mons.httpclient.DefaultHttpMethodRe...  Post 和 Get 方法的区别 get 是从服务器上获取数据,post 是向服务器传送数据。 get 是把参数数据队列加到提交表单的 ACTION 属性所指的 URL 中, 值和表单内...

我要回帖

更多关于 postmethod 添加参数 的文章

 

随机推荐