我非常熟悉Android休息网络服务我希望从我的android程序中连接其余网络服务,我编写以下代码:
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
HttpGet httpGet = new HttpGet("http://***********:8000/sap/bc/srt/rfc/sap/z_customer_lookup1/800/z_customer_lookup1/z_customer_lookup1_bind&sap-user=*******&sap-password=********");
但是当我运行此代码时,我收到登录错误消息,如何在Android Rest Web服务中提供身份验证。
答案 0 :(得分:0)
尝试此代码以使用http post方法:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
nameValuePairs.add(new BasicNameValuePair("request", "login"));
nameValuePairs.add(new BasicNameValuePair("user_name", user_name));
nameValuePairs.add(new BasicNameValuePair("password", pass));
DefaultHttpClient client = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpParams params = client.getParams();
HttpConnectionParams.setConnectionTimeout(params, 3000);
HttpConnectionParams.setSoTimeout(params, 3000);
HttpResponse httpResponse = client.execute(httppost);
result=EntityUtils.toString(httpResponse.getEntity());`