Andriod呼び出しhttp要求

1824 ワード

          //   HttpPost  
		HttpPost httpPost = new HttpPost(
				"http://180.153.1.1:8080/mybankGateway/gateway/queryProductType");

		//     
		List<NameValuePair> params = new ArrayList<NameValuePair>();
		params.add(new BasicNameValuePair("query", "   "));

		//      
		HttpEntity entity = null;
		try {
			entity = new UrlEncodedFormEntity(params, HTTP.UTF_8);
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		//       
		httpPost.setEntity(entity);
		//   HttpClient  
		HttpClient httpClient = new DefaultHttpClient();
		//     
		httpClient.getParams().setParameter(
				CoreConnectionPNames.CONNECTION_TIMEOUT, 30000);
		//     
		httpClient.getParams().setParameter(CoreConnectionPNames.SO_TIMEOUT,
				30000);
		try {
			//   HttpResponse  
			HttpResponse httpResp = httpClient.execute(httpPost);
			//         
			if (httpResp.getStatusLine().getStatusCode() == 200) {
				//        
				String result = EntityUtils.toString(httpResp.getEntity(),
						"UTF-8");
				Log.i("HttpPost", "HttpPost      ,      :");
				Log.i("result", result);
				System.err.println(result);
			} else {
				Log.i("HttpPost", "HttpPost      ");
			}
		} catch (ConnectTimeoutException e) {
			e.printStackTrace();
		} catch (ClientProtocolException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}