3
我想向webApi
網址發出請求,您已經編寫了以下代碼,並且我在NameValuePair
對象中有我的參數。如何將URL參數從NameValuePair添加到HttpPost請求
現在我不知道如何將這些參數添加到基礎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;
}