日期:2014-05-17 浏览次数:20882 次
package org.cl.impl;
import java.io.*;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.utils.URIUtils;
import org.apache.http.client.utils.URLEncodedUtils;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.cl.vo.Tuser;
public class ITuserImpl {
public static Tuser login(String logonName,String password) throws URISyntaxException {
String url="http://host:port/web_xml_interface/user_logon.xml?" +
"logonName="+logonName+"&password="+password+"&" +
"platformId=010006&logonType=2&Ver=sdk_001" ;
HttpClient httpclient = new DefaultHttpClient();
List<NameValuePair> qparams = new ArrayList<NameValuePair>();
qparams.add(new BasicNameValuePair("logonName", logonName));
qparams.add(new BasicNameValuePair("password", password));
//HttpPost post = new HttpPost("url");
Tuser requestUser = new Tuser();
requestUser.setlogonName(logonName);
requestUser.setPassword(password);
URI uri = URIUtils.createURI("http","host:port",-1,"/web_xml_interface/user_logon.xml",
URLEncodedUtils.format(qparams, "UTF-8"), null);
HttpGet httpget =new HttpGet(url);
InputStream stream = null;
try{
//HttpResponse status = httpclient.execute(post);
HttpResponse response = httpclient.execute(httpget);
stream = response.getEntity().getContent();
if(stream != null){
BufferedReader reader=new BufferedReader(new InputStreamReader(stream));
String htmlRet="";
String tmp = null;
while((tmp=reader.readLine())!=null){
htmlRet+=tmp+"\r\n";
}
System.out.println(new String(htmlRet.getBytes("ISO-8859-1"),"GBK"));
stream.close();
}
}catch (IOException e) {
e.printStackTrace();