惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

GbyAI
GbyAI
T
Tenable Blog
Webroot Blog
Webroot Blog
L
Lohrmann on Cybersecurity
S
Securelist
S
Schneier on Security
NISL@THU
NISL@THU
Know Your Adversary
Know Your Adversary
C
Cybersecurity and Infrastructure Security Agency CISA
T
The Exploit Database - CXSecurity.com
L
LINUX DO - 热门话题
C
CXSECURITY Database RSS Feed - CXSecurity.com
O
OpenAI News
I
Intezer
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
TaoSecurity Blog
TaoSecurity Blog
S
Secure Thoughts
Application and Cybersecurity Blog
Application and Cybersecurity Blog
P
Privacy International News Feed
H
Hacker News: Front Page
N
Netflix TechBlog - Medium
M
MIT News - Artificial intelligence
博客园 - Franky
PCI Perspectives
PCI Perspectives
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Microsoft Azure Blog
Microsoft Azure Blog
MongoDB | Blog
MongoDB | Blog
L
LangChain Blog
P
Proofpoint News Feed
S
Security Affairs
WordPress大学
WordPress大学
The Last Watchdog
The Last Watchdog
S
SegmentFault 最新的问题
小众软件
小众软件
F
Full Disclosure
博客园 - 叶小钗
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
T
The Blog of Author Tim Ferriss
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
Security Latest
Security Latest
P
Proofpoint News Feed
月光博客
月光博客
T
Tailwind CSS Blog
Scott Helme
Scott Helme
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google Online Security Blog
Google Online Security Blog
T
Threat Research - Cisco Blogs
Help Net Security
Help Net Security
Project Zero
Project Zero

博客园 - blueKnight

Java根据WSDL生成request的SOAP报文模板 Java解析Soap XML HttpClient示例 【转】C++标准库和标准模板库 dotNetFrameWork 3.5SP1离线安装 笔记本电脑win7创建WIFI热点 【转】Oracle免客户端For .Net(增加分析Devart和DataDirect) 【转】ORA-00257 archiver error. 错误的处理方法 数学表达式与二叉树 FIREFOX不支持font-family: webdings;怎么办? "5","6"排序上下箭头问题 【转】Eclipse插件开发之基础篇(1) 插件开发的基础知识 http MIME大全 在iframe里的页面编写js,实现在父窗口上创建动画效果展开和收缩的div(不变动iframe父窗口代码) FreeMarker示例 转:用XML编写EXCEL文件 【网摘】BI系统(Business Intelligence) js获取周.html 关于j2ee工程发布到was上后,部分更新,例修改web.xml配置文件不起作用的原因解析 SSI(Struts2+Spring2+IBatis)代码生成器(纯Java版)
【转】HttpClient使用Post和Get提交参数
blueKnight · 2014-12-08 · via 博客园 - blueKnight
package httpclient;

import java.io.IOException;
import java.net.URLEncoder;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;

public class HttpClientTest {

	public static void main(String[] args) throws Exception{
		String url = "/webservices/DomesticAirline.asmx/getDomesticAirlinesTime";
		String host = "www.webxml.com.cn";
		String param = "startCity="+URLEncoder.encode("杭州", "utf-8")+"&lastCity=&theDate=&userID=";
		HttpClient httpClient = new HttpClient();
		httpClient.getHostConfiguration().setHost(host, 80, "http");		
		
		HttpMethod method = getMethod(url, param);
		//HttpMethod method = postMethod(url);
		
		httpClient.executeMethod(method);
		
		String response = method.getResponseBodyAsString();
		//String response = new String(method.getResponseBodyAsString().getBytes("ISO-8859-1"));				
		System.out.println(response);
	}
	
	private static HttpMethod getMethod(String url,String param) throws IOException{
		GetMethod get = new GetMethod(url+"?"+param);
		get.releaseConnection();
		return get;
	}
		
	private static HttpMethod postMethod(String url) throws IOException{ 
		PostMethod post = new PostMethod(url);
		post.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");  
		NameValuePair[] param = { new NameValuePair("startCity","杭州"),
				new NameValuePair("lastCity","沈阳"),
				new NameValuePair("userID",""),
				new NameValuePair("theDate","")	} ;
    	post.setRequestBody(param);
    	post.releaseConnection();
		return post;
	}
}

 
如果PostMethod提交的是中文字符,需要加上相应的编码格式:  post.setRequestHeader("Content-Type","application/x-www-form-urlencoded;charset=gbk");  
如果GetMethod提交的参数有中文字符,需要先转换成utf-8格式:  URLEncoder.encode("杭州", "utf-8");