Iphone IOS中带有ssl API的oauth请求

Iphone IOS中带有ssl API的oauth请求,iphone,api,ssl,oauth,oauth-2.0,Iphone,Api,Ssl,Oauth,Oauth 2.0,我需要在IOS中使用ssl API执行oauth请求。我尝试了afnetworking框架,但它不起作用 通过使用这个库,我在android中也做了同样的事情 我需要在iphone上做同样的事情,但我没有从任何地方得到正确的想法。 如果有人做过同样的事情,请帮我解决这个问题。谢谢 这是我的密码 APIClient.class public class APIClient { private static String Base_URL = "http://**************:8080"

我需要在IOS中使用ssl API执行oauth请求。我尝试了afnetworking框架,但它不起作用

通过使用这个库,我在android中也做了同样的事情

我需要在iphone上做同样的事情,但我没有从任何地方得到正确的想法。 如果有人做过同样的事情,请帮我解决这个问题。谢谢

这是我的密码

APIClient.class

public class APIClient {
private static String Base_URL = "http://**************:8080";
private static AsyncHttpClient client = new AsyncHttpClient(false, 80, 443);

@SuppressWarnings("deprecation")
public static void prepareAllRequest() {
    // clearBasicAuth deprecated, might will be used with
    // clearCredentialsProvider instead
    client.clearBasicAuth();
}

public static void prepareAuthRequest(String access_token) {
    prepareAllRequest();
    client.addHeader("Authorization", "Bearer " + access_token);
}

public static void get(String url, String access_token,
        AsyncHttpResponseHandler responseHandler) {
    prepareAuthRequest(access_token);
    client.get(getAbsoluteUrl(url), responseHandler);
}

public static void post(String url, String access_token,
        RequestParams params, AsyncHttpResponseHandler responseHandler) {
    prepareAuthRequest(access_token);
    client.post(getAbsoluteUrl(url), params, responseHandler);
}

public static void post_auth(String url, RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    client.setBasicAuth("**************", "**************");
    client.post(getAbsoluteUrl(url), params, responseHandler);
}

public static void register(RequestParams params,
        AsyncHttpResponseHandler responseHandler) {
    prepareAllRequest();
    client.post(getAbsoluteUrl("/signup"), params, responseHandler);
}

public static void delete(String url, String access_token,
        RequestParams params, AsyncHttpResponseHandler responseHandler) {
    prepareAuthRequest(access_token);
    client.post(getAbsoluteUrl(url), params, responseHandler);
}

private static String getAbsoluteUrl(String relativeUrl) {
    return Base_URL + relativeUrl;
}
}
主课

public class MainActivity extends Activity {

private JsonHttpResponseHandler GGHandler;
public String access_token = "";
public String refresh_token = "";
private String user_code = "**************";
private String user_email = "**************";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    authentication();

}

private void authentication() {

    final RequestParams param2 = new RequestParams();
    param2.put("username", "************");
    param2.put("password", "************");
    param2.put("client_id", "************");
    param2.put("client_secret", "************");
    param2.put("scope", "read");
    param2.put("grant_type", "password");

    GGHandler = new JsonHttpResponseHandler() {

        public void onFailure(int i, Header aheader[], String s,
                Throwable throwable) {
            Log.e("CANCER", (new StringBuilder()).append(i).append(" - ")
                    .append(s).toString());
            Log.e("CANCER", throwable.getMessage());
            APIClient.post_auth("/oauth/token", param2, GGHandler);

        }

        public void onFailure(int i, Header aheader[], Throwable throwable,
                JSONObject jsonobject) {
            StringBuilder stringbuilder = (new StringBuilder()).append(i)
                    .append(" - ");
            if (jsonobject == null) {
                // aheader = "";
            } else {
                Log.e("test", "data from i :" + i);
                // aheader = jsonobject.toString();
            }
            Log.e("test", "data from failer :" + jsonobject.toString());

            Log.e("CANCER2", stringbuilder.append(aheader).toString());
            Log.e("CANCER2", throwable.getMessage());
            if (i == 0) {
                APIClient.post_auth("/oauth/token", param2, GGHandler);
            }
            if (i == 400) {

                Toast.makeText(getApplicationContext(),
                        "data is not send ", 1).show();

            }
        }

        public void onSuccess(int i, Header aheader[], JSONObject jsonobject) {

            try {

                access_token = jsonobject.getString("access_token");
                refresh_token = jsonobject.getString("refresh_token");

                Log.e("test",
                        "data from jsonobject :"
                                + jsonobject.getString("access_token"));
                Log.e("test",
                        "data from jsonobject :"
                                + jsonobject.getString("refresh_token"));


                GetandDisplayListofscene();

                Log.e("Status code",
                        (new StringBuilder()).append("Status code is: ")
                                .append(i).toString());

                // Misplaced declaration of an exception variable
            } catch (Exception e) {
                e.printStackTrace();
            }
        }

    };
    APIClient.post_auth("/oauth/token", param2, GGHandler);

}


private void signup() {

    RequestParams requestparams;

    requestparams = new RequestParams();
    requestparams.put("username", "************");
    requestparams.put("password", "************");
    requestparams.put("email", "************");
    Log.e("Register isSocial",
            (new StringBuilder()).append("").append("false").toString());
    Log.e("Register username", user_email);

    APIClient.register(requestparams, new TextHttpResponseHandler() {

        public void onFailure(int i, Header aheader[], String s1,
                Throwable throwable) {
            Log.e("Post",
                    (new StringBuilder())
                            .append("Failed with status Code ").append(i)
                            .toString());
            Log.e("Post",
                    (new StringBuilder()).append("Failed with response ")
                            .append(throwable).toString());
        }

        public void onSuccess(int i, Header aheader[], String s1) {

            Log.e("test", "data in  sign up :" + s1);
            authentication();

        }
    });
}
}