English 中文(简体)
如何从甲型六氯环己烷和甲型六氯环己烷的网络服务?
原标题:how to call RESTful web service from android?

I have written REST web service in netbean IDE using jersey framework and java. For every request user need to provide username and password , I know the authentication is not good. Using curl command like : curl -u username:password -X PUT http://localhsot:8080/user

Now I want to call REST web service from android class.What should I write? I am new to android. I have a android class which use DefaultHttpClient and CredentialUsernameAndPassword. But when i run in eclipse, sometime I get runtime exception or sdk exception.

是否有任何人向我提供守则和建议样本?

感谢

最佳回答

你们是否使用基本认证? 如果是的话:使用。

if (username != null && password != null) {
            client.getCredentialsProvider().setCredentials(
                    new AuthScope(null, -1),
                    new UsernamePasswordCredentials(username, password));
        }

或者你可以把标题中的人增加为“主人”(“Authentication”),“Basic”+Base64EncodedString(用户名称、护照);

你们正在使用Proxy认证。 为什么?

本条也可有所帮助:

link

也可以看一看遗嘱授权。 有一些话题说,它并不支持甲状腺或某种东西,但我确信,如果你需要的话,你可以做一个工作。

问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签