4

我正在尝试向 url 发出请求,你已经编写了以下代码,并且我在一个对象webApi中有我的参数。NameValuePair

现在我不知道如何将这些参数添加到基本 uri 我必须通过连接字符串手动完成吗?或者有没有其他方法,请帮忙。

private static final String apiBaseUri="http://myapp.myweb.com/path?";

private boolean POST(List<NameValuePair>[] nameValuePairs){
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(apiBaseUri); 
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs[0]));
    HttpResponse response = httpclient.execute(httppost);
    String respond = response.getStatusLine().getReasonPhrase();
    Log.d("MSG 3 > ",respond);
    return true;
}
4

1 回答 1

4

您可以使用它来将参数添加到 url

 nameValuePairs.add(new BasicNameValuePair("name",value));
  String UrlString = URLEncodedUtils.format(nameValuePairs, "utf-8");

   url +=UrlString;
于 2013-10-24T01:12:49.027 回答