百度云存储测试

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 void demo1() throws ClientProtocolException, IOException {
        // 1、 创建httpClient对象
        HttpClient client = HttpClients.createDefault();

        // 2、 请求对象
        HttpPost httpPost = new HttpPost(
                "http://api.map.baidu.com/geodata/v3/geotable/create");

        // 3、 绑定参数
        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        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(new UrlEncodedFormEntity(nameValuePairs,
                Charsets.UTF_8));

        // 4、 发送请求
        HttpResponse httpResponse = client.execute(httpPost);

        // 5、 打印结果数据
        HttpEntity httpEntity = httpResponse.getEntity();
        System.out.println(EntityUtils.toString(httpEntity));
    }

    @Test
    // 查询表
    public void demo2() throws ClientProtocolException, IOException {
        // 1、 创建httpClient对象
        HttpClient client = HttpClients.createDefault();

        // 2、 请求对象
        HttpGet httpGet = new HttpGet(
                "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));
    }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值