少年阿賓

          那些青春的歲月

            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 = " 
           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"));
           }

          }

          主站蜘蛛池模板: 南华县| 高雄县| 呼伦贝尔市| 安徽省| 宿州市| 丘北县| 郸城县| 内黄县| 高雄市| 大洼县| 衡水市| 灵川县| 湄潭县| 屏山县| 团风县| 黑水县| 东兴市| 北海市| 邵东县| 平阴县| 南昌市| 肃南| 吐鲁番市| 蓬溪县| 东山县| 吕梁市| 白水县| 临邑县| 游戏| 阳东县| 齐河县| 班玛县| 婺源县| 贵德县| 德安县| 虞城县| 屯昌县| 五台县| 呼伦贝尔市| 平昌县| 永德县|