最简单的Java Post请求

来源:互联网 发布:云转码软件 编辑:程序博客网 时间:2024/06/05 14:13

直接上代码


import java.io.IOException;import org.apache.commons.httpclient.HttpClient;import org.apache.commons.httpclient.HttpException;import org.apache.commons.httpclient.methods.PostMethod;public class PostTest {public static void main(String[] args) {// 测试代码HttpClient client = new HttpClient();String url = "http://my.csdn.net/the_direwolf";PostMethod method = new PostMethod(url);// method.addParameter("username","xxxxxxx@126.com");// method.addParameter("password", "xxxxxx");try {client.executeMethod(method);String response = method.getResponseBodyAsString();System.out.println(response);} catch (HttpException e) {e.printStackTrace();} catch (IOException e) {e.printStackTrace();}}}

需引用的jar包:

commons-httpclient-3.0.jar和commons-codec-1.8.jar  (点击下载)


0 0
原创粉丝点击