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);
请告诉我如何发送参数。