我正在尝试向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;
}
答案 0 :(得分:3)
您可以使用它将参数添加到网址
nameValuePairs.add(new BasicNameValuePair("name",value));
String UrlString = URLEncodedUtils.format(nameValuePairs, "utf-8");
url +=UrlString;