调用json数据接口

package com.sz.kcygl.web.controller.front; 

import java.io.BufferedReader; 
import java.io.InputStream; 
import java.io.InputStreamReader; 

import junit.framework.TestCase; 

import org.apache.commons.httpclient.HttpClient; 
import org.apache.commons.httpclient.methods.PostMethod; 

public class AppListJsonControllerTest extends TestCase { 



public void testQuery() throws Exception{ 
HttpClient client = new HttpClient(); 
//	 PostMethod get = new PostMethod("http://219.233.185.46:8090/front/getAppList.do"); 
PostMethod get = new PostMethod("http://localhost:8088/front/getAppList.do"); 
get.setDoAuthentication( true ); 
get.setRequestHeader("Content-Type", "text/html;charset=UTF-8"); 
String requestString = "{\"terminalType\":\"Ipad\",\"userToken\":\"1\",\"request\":{\"companyId\":\"E84B0D0A05060FA2E040A8C0400022B6\",\"terminalType\":\"2\"}}"; 
get.setRequestBody(requestString); 
int status = client.executeMethod( get ); 
InputStream is = get.getResponseBodyAsStream(); 
BufferedReader br = new BufferedReader(new InputStreamReader(is)); 
String line = ""; 
StringBuilder sb = new StringBuilder(); 
while((line = br.readLine()) != null){ 
    sb.append(line + "\n"); 
} 
System.out.println("request:\n"+requestString); 
System.out.println("status:"+status); 
System.out.println("response:\n"+sb.toString()); 
} 
} 

 

你可能感兴趣的:(json)