少年阿宾

那些青春的岁月

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  500 Posts :: 0 Stories :: 135 Comments :: 0 Trackbacks

package org.abin.lee.file;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.TestCase;
import net.sf.json.JSONObject;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;

public class QueryCustomerManagerTestCase extends TestCase {
 
 private static final String jsonServerUrl = "http://10.10.10.10:1010/portal/mobile/";
 
 static DefaultHttpClient client = new DefaultHttpClient();

 public static String sendReq(String method, String jsonReq)
   throws ClientProtocolException, IOException {
  HttpPost post = new HttpPost(jsonServerUrl + method);
  List<NameValuePair> nvps = new ArrayList<NameValuePair>();
  nvps.add(new BasicNameValuePair("json", jsonReq));

  post.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));

  HttpResponse response = client.execute(post);
  HttpEntity entity = response.getEntity();
  String entityStr = EntityUtils.toString(entity);

  return entityStr;
 }

 /**
  * 查询产品客户经理接口
  */
 public void testQueryCustomerManager() throws ClientProtocolException,
   IOException {
  String jsonReq = "{" + "RequestID:'11111',"+ "ProductID:'SC9904348'," + "timestamp:'20120416121200',"
    + "Hashcode:'1324546asdfgfhr65432wsdfgt654eds'" + "}";

  String resStr = this.sendReq("query-customer-manager-json!queryCustomerManager.action", jsonReq);

  System.out.println(resStr);

  assertNotNull(resStr);
//  JSONObject json = JSONObject.fromObject(resStr);
//  assertNotNull(json.get("requestID"));
 }

}

posted on 2012-05-29 12:28 abin 阅读(1418) 评论(0)  编辑  收藏 所属分类: httpClient

只有注册用户登录后才能发表评论。


网站导航: