0
try {
  String auth = android.util.Base64.encodeToString((“USERNAME” + ":" + “PASSWORD”).getBytes("UTF-8"), android.util.Base64.NO_WRAP);
  HttpParams httpParameters = new BasicHttpParams();

  HttpPost request = new HttpPost(“URL” + ” ? action = xxx”);
  request.addHeader("Authorization", "Basic " + auth);
  httpParameters.setParameter("password", "xxxx");
  httpParameters.setParameter("email", "xxxxxxx");
  HttpConnectionParams.setSoTimeout(httpParameters, SOCKET_TIMEOUT_MS);
  HttpClient client = new DefaultHttpClient(httpParameters);

  HttpResponse response = client.execute(request);
  String userAuth = EntityUtils.toString(response.getEntity());
  Log.i("", "Data. in login.." + userAuth);
} catch (Exception e) {
  Log.i("", "Error.." + e);
}

在这里,我设置了这个,但根据输出参数没有到达服务器端......

4

1 回答 1

0

试试这个代码

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(this.url);


{
    List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
    nameValuePair.add(new BasicNameValuePair("requestcode", "10"));
    nameValuePair.add(new BasicNameValuePair("devicetype", "phone"));
    nameValuePair.add(new BasicNameValuePair("locale", "in"));
    nameValuePair.add(new BasicNameValuePair("username", "amrit@pqr.com"));
    nameValuePair.add(new BasicNameValuePair("password", "abc"));

    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    StatusLine statusLine = response.getStatusLine();
    int statusCode = statusLine.getStatusCode();
    Log.d("RestClient", "Status Code : " + statusCode);

    HttpEntity entity = response.getEntity();

    Log.d("Response", EntityUtils.toString(entity));
}
于 2014-10-10T09:59:55.350 回答