/**
* class name:HttpConnect<BR>
* class description:get something to web <BR>
* PS: <BR>
*
* @version 1.00 2011/09/21
* @author CODYY)peijiangping
*/
public class HttpConnect {
public int getDataAsInt(List<NameValuePair> params) {
int result = CONST.HTTP_ERROR;
try {
httpRequest = new HttpPost(url);
httpRequest.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
httpResponse = httpClient.execute(httpRequest);
StatusLine status = response.getStatusLine();
if (status.getStatusCode() != 200) {
throw new ApiException("Invalid response from server: "
+ status.toString());
}
InputStream is = new FileInputStream(file.getValue());
byte[] buffer = new byte[1024];
int len = 0;
while ((len = is.read(buffer)) != -1) {
outStream.write(buffer, 0, len);
}
// 得到响应码
int res = conn.getResponseCode();
String line = null;
InputStream in = conn.getInputStream();
InputStreamReader isReader = new InputStreamReader(in);
BufferedReader bufReader = new BufferedReader(isReader);
while((line = bufReader.readLine())!=null)
data += line;
if (res != 200) {
throw new ApiException("Invalid response from server: "
+ data);
}
in.close();
outStream.close();
conn.disconnect();
} catch (IOException e) {
throw new ApiException("Problem communicating with API", e);
}