0
String url = "https://api.assembla.com/v1/tasks.json";

HttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(url);

httpGet.addHeader("Accept", "application/json");
httpGet.addHeader("Content-type", "application/json");
httpGet.addHeader("X-Api-key", "some_key");
httpGet.addHeader("X-Api-secret", "some_secret");
BufferedReader bufferedReader = null;
String jsonText = null;

HttpResponse response = httpClient.execute(httpGet);

bufferedReader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

String line = "";

while ((line = bufferedReader.readLine()) != null) {
    jsonText = line;

此代码从日期获取任务。到目前为止,我想在 GET 中进行 POST。我怎样才能做到这一点?

我想做 HTTP 客户端 POST 方法:

List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM"));
urlParameters.add(new BasicNameValuePair("cn", ""));
urlParameters.add(new BasicNameValuePair("locale", ""));
urlParameters.add(new BasicNameValuePair("caller", ""));
urlParameters.add(new BasicNameValuePair("num", "12345"));

post.setEntity(new UrlEncodedFormEntity(urlParameters));

HttpResponse response = client.execute(post);

请告诉我如何发送参数。

4

2 回答 2

0

您必须在 url 中保留参数,如下所示..

String url = "http://www.example.com/page?key=value";
GetMethod method = new GetMethod(url);
于 2014-05-06T12:26:25.573 回答
0
URI url = new URIBuilder().setScheme("https")
            .setHost("api.assembla.com").setPath("/v1/tasks.json")
            .setParameter("per_page", "100")
            .setParameter("from", "Some_Date")
            .setParameter("to", "Some_Date").build();

使用它,我们可以使用 httpClient heetGet 方法添加参数列表我认为它可能有用

于 2014-05-07T09:02:44.823 回答