0

我对 Android rest web-services 非常陌生,我想从我的 android 程序中连接 Rest web-services,为此我编写了以下代码:

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 服务中提供身份验证。

4

1 回答 1

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());`
于 2012-08-21T07:22:48.860 回答