---
title: "Http方式请求web Service"
author: "mapengfei00099"
date: "2012-07-28T14:05:29Z"
tags: []
categories: ["编程语言"]
slug: "http-web-service"
draft: false
lastmod: "2012-07-28T14:06:13Z"
id: 1610266
url: "https://mapengfei00099.iteye.com/blog/1610266"
---

```
try {
		

			HttpPost httpost = new HttpPost("http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx");
			StringEntity myEntity = new StringEntity(FileUtils.readFileToString(new File("a.txt")));
            httpost.setHeader("SOAPAction", "http://WebXml.com.cn/getRegionCountry");
            httpost.setHeader("Content-Type", "text/xml; charset=utf-8");
            httpost.setEntity(myEntity);
    
            for (Header string : httpost.getAllHeaders()) {
				System.out.println(string.getName()+":"+string.getValue());
			}
            System.out.println("-------------------------");
			HttpResponse response = httpclient.execute(httpost);
			HttpEntity entity = response.getEntity();
			String resString = EntityUtils.toString(entity);
				     for (Header string : response.getAllHeaders()) {
				    		System.out.println(string.getName()+":"+string.getValue());
				}
			System.out.println("response content:" + resString);

		} finally {
		
			httpclient.getConnectionManager().shutdown();
		}
```