API调用适用于ios,但不适用于邮递员和android

时间:2019-04-23 18:53:01

标签: java android api postman

我正在Objective-C和android中调用相同的api。 但是它可以在Objective-C中工作,而不能在android和postman中工作。 这是objective-c的代码

NSString *string = [NSString stringWithFormat:@"%@?option=com_globaltalk&task=api.getProfile", userBaseURL];
    NSURL *url = [NSURL URLWithString:string];
    NSURLRequest *request = [NSURLRequest requestWithURL:url];

    AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];
    operation.responseSerializer = [AFJSONResponseSerializer serializer];

    [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, NSDictionary* responseObject) {
...
}

这是Objective-c的输出

{
    activation = "";
    block = 0;
    email = "***";
    groupTitle = "SXL - HC1 - B";
    groups =     {
        14 = 14;
    };
    guest = 0;
    id = 476;
    lastResetTime = "0000-00-00 00:00:00";
    lastvisitDate = "2019-04-23 12:54:23";
    name = "\U4f59\U4f73\U8431";
    options =     {
        companyid = 10448;
        domain = xwyy;
        "history_limit" = 5;
        key = ***;
        "save_history" = 0;
        studentgroupid = "";
        teachergroupid = 11;
        url = "***";
        userid = ***;
        userpassword = ***;
    };
    otep = "";
    otpKey = "";
    params = "{\"admin_style\":\"\",\"admin_language\":\"\",\"language\":\"\",\"editor\":\"\",\"helpsite\":\"\",\"timezone\":\"\"}";
    password = "***";
    "password_clear" = "";
    registerDate = "2019-04-21 02:41:26";
    requireReset = 0;
    resetCount = 0;
    sendEmail = 0;
    username = ***;
}

这是Android的代码

RequestParams params = new RequestParams();
        params.put("option", "com_globaltalk");
        params.put("task", "api.getProfile");

        client.get(userBaseURL, params, new JsonHttpResponseHandler() {
            @Override
            public void onSuccess(int statusCode, org.apache.http.Header[] headers, JSONObject response) {
                try {

输出与Objective-C类似,但id,名称,用户名,电子邮件...为空

api端点的完整URL为

http://kidoABC.com/index.php?option=com_globaltalk&task=api.getProfile

在调用此api之前,还有一个api

http://kidoABC.com/index.php?option=com_jbackend&view=request&action=post&module=user&resource=login&username=Eva2&password=123456

第一个api在android和postman上运行良好,但是第二个api则不起作用。

感谢您阅读我的问题

0 个答案:

没有答案