package cn.itcast.baidumap;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.codec.Charsets;
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.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import org.junit.Test;//云存储 测试
public class BaiduLBSStorageTest {
@Test//建立表 geotable
public voiddemo1() throws ClientProtocolException, IOException {//1、 创建httpClient对象
HttpClient client =HttpClients.createDefault();//2、 请求对象
HttpPost httpPost = newHttpPost("http://api.map.baidu.com/geodata/v3/geotable/create");//3、 绑定参数
List nameValuePairs = new ArrayList();
nameValuePairs.add(new BasicNameValuePair("name", "mytable2"));
nameValuePairs.add(new BasicNameValuePair("geotype", "1"));
nameValuePairs.add(new BasicNameValuePair("is_published", "1"));
nameValuePairs.add(new BasicNameValuePair("ak","zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf"));
httpPost.setEntity(newUrlEncodedFormEntity(nameValuePairs,
Charsets.UTF_8));//4、 发送请求
HttpResponse httpResponse =client.execute(httpPost);//5、 打印结果数据
HttpEntity httpEntity =httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
@Test//查询表
public voiddemo2() throws ClientProtocolException, IOException {//1、 创建httpClient对象
HttpClient client =HttpClients.createDefault();//2、 请求对象
HttpGet httpGet = newHttpGet("http://api.map.baidu.com/geodata/v3/geotable/list?ak=zbLsuDDL4CS2U0M4KezOZZbGUY9iWtVf");//3、发送请求
HttpResponse httpResponse =client.execute(httpGet);//4、 打印结果数据
HttpEntity httpEntity =httpResponse.getEntity();
System.out.println(EntityUtils.toString(httpEntity));
}
}