android - 使用给定自定义 api 的 Http Post android 登录

标签 android authentication http-post

我正在尝试使用登录表单登录网站并在我的应用程序中提交按钮。我得到了以下 api 信息:

api 已设置在 consumer.api.mobodev.terryinc.com

使用此 api,我尝试使用用户名登录。已为 api 调用提供以下信息:

Login with Username The Login with Username service is provided for existing Consumers to login using their username and password. The username will be either an email address or mobile phone number depending on how the Consumer had initially registered. Login with Username will typically be used when logging into a second or subsequent Device, or via the browser etc. This is because in the normal process flow, a Consumer will register and the Access Token will be returned and cache by the Client Application. The Access Token is then used when starting the application instead of getting the Consumer to log in again. Calling the Login with Username logs the Consumer into the system and creates and returns a valid OAuth Access Token. The returned OAuth Access Token can then be used in for subsequent API calls to identify the Consumer of the Client Application. Attributes Attribute Value

  • 路径/v3/logins 支持
  • 格式化 JSON、XML HTTP
  • 方法 POST
  • 安全不
  • 限速
  • 无缓存
  • 超时待定 -HTTP 代码 200 - 确定 400 - 错误请求。
    500 - 内部服务器错误。

下面是我在主要 Activity 中编写的代码:

 HttpClient httpclient = new DefaultHttpClient();

**HttpPost httppost = new HttpPost("consumer.api.mobodev.terryinc.com");**


    try {
        // Add user name and password
     EditText uname = (EditText)findViewById(R.id.username);
     String username = uname.getText().toString();

     EditText pword = (EditText)findViewById(R.id.password);
     String password = pword.getText().toString();

        List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3);
        nameValuePairs.add(new BasicNameValuePair("grant_type","password"));
        nameValuePairs.add(new BasicNameValuePair("username", username));
        nameValuePairs.add(new BasicNameValuePair("password", password));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // Execute HTTP Post Request
        Log.w("Post", "Execute HTTP Post Request");
        HttpResponse response = httpclient.execute(httppost);

        String str = inputStreamToString(response.getEntity().getContent()).toString();
        Log.w("Before Post", str.toString());

我的问题是我在创建 httpPost 对象时是否使用了正确的 url?

请帮忙,因为我不知道如何解释 api 文档。

最佳答案

在 Firefox 中,我使用这个很棒的插件来模拟和测试 API 调用 - 它叫做 Rest Client ,我建议您先在此处测试 API,然后再编写任何代码。

关于android - 使用给定自定义 api 的 Http Post android 登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11288154/

相关文章:

android - Android GCM 上的 registeredOnServer 状态何时过期?

java - Spring安全登录总是200

iphone - 从 Iphone native 客户端使用 Google App Engine 进行身份验证

java - Android:无法发送http post

javascript - 从使用 Trigger.io 构建的移动应用程序发送发布请求

android - 失败 : dlopen failed: cannot locate symbol "signal" referenced by "libSDL2.so"

java - 如何在线性布局中设置随机 TextView 的位置?

reactjs - 如何在 react 应用程序中检测过期的用户 session ?

audio - 如何使用来自 blackberry 5.0 的 HTTP POST 上传音频文件?

安卓 : Fullscreen system visibility screws up window insets