httpclient发送soap请求

不带请求参数 的请求方式:

 

	
	public String getDealChannels(){
		try {
			//the webservice url
			String url = HOST+"service/getDealChannels";
			PostMethod pm = new PostMethod(url);
			HttpClient httpclient = new HttpClient();

			HttpClientParams params = new HttpClientParams();

			//set request time out(millisecond)
			params.setSoTimeout(25000);

			httpclient.setParams(params);
			
			//request to webservice, get response code
			int result = httpclient.executeMethod(pm);
			if (result != 200) {
				System.out.println("Error. code: " + result);
				return null;
			}

			//get response
			InputStream xmlStream = pm.getResponseBodyAsStream();
			return getString(xmlStream);
		} catch (Exception e) {
			System.out.println("Exception: " + e.getLocalizedMessage());
			return null;
		}
	
	}

 

请求参数 的请求方式:

 

	
	public String getDealListByVertical(String verticalName){
		try {
			//the webservice url
			String url = HOST+"service/getDealListByVertical";
			PostMethod pm = new PostMethod(url);
			HttpClient httpclient = new HttpClient();

			HttpClientParams params = new HttpClientParams();
			
			//JAXB class
			IpadVerticalRequestJAXB re = new IpadVerticalRequestJAXB();
			re.setVerticalName(verticalName);
			re.setItemsPerPage(10);
			re.setPageNumber(1);
			re.setOrderBy("title");
			re.setIsDesc(true);
			
			//marshall to xml string type
			String request = marshallRequest(re, re.getClass());

			//set request time out(millisecond)
			params.setSoTimeout(25000);

			httpclient.setParams(params);
			
			//set xml String
			RequestEntity reqE = new StringRequestEntity(request);
			pm.setRequestEntity(reqE);
			
			//request to webservice, get response code
			int result = httpclient.executeMethod(pm);
			if (result != 200) {
				System.out.println("Error. code: " + result);
				return null;
			}

			//get response
			InputStream xmlStream = pm.getResponseBodyAsStream();
			return getString(xmlStream);
		} catch (Exception e) {
			System.out.println("Exception: " + e.getLocalizedMessage());
			return null;
		}
	
	}
	

你可能感兴趣的:(httpclient)