简体   繁体   English

如何从 android 应用程序向 WHMCS 安装发送正确的发布请求?

[英]How to send a proper post request to WHMCS installation from android app?

I am trying to send an AddClient post request to my WHMCS installation through my android app but it keeps returning "result=error;message=You did not enter your first name".我正在尝试通过我的 android 应用程序向我的 WHMCS 安装发送 AddClient 发布请求,但它一直返回“结果 = 错误;消息 = 你没有输入你的名字”。

I get it to authenticate successfully but it doesnt seem to be posting the jsonObject I am sending it.我让它成功验证,但它似乎没有发布我发送的 jsonObject。

Here is a link to WHMCS api documentation: https://developers.whmcs.com/api-reference/addclient/这是 WHMCS api 文档的链接: https://developers.whmcs.com/api-reference/addclient/

public void createWHMCSUser(final String emailID, final String random, final String uid) {

    final String AccessUserKey = "abc123";
    final String AccessKey = "abc123";
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                URL url = new URL("http://whmcs.installation.com/includes/api.php?action=AddClient&username=abc123&password=abc123&accesskey=abc123");
                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestMethod("POST");
                conn.setRequestProperty("Content-Type", "application/json");
                conn.setRequestProperty("Accept","application/json");
                conn.setDoOutput(true);
                conn.setDoInput(true);

                JSONObject jsonParam = new JSONObject();
                jsonParam.put("action", "AddClient");
                jsonParam.put("identifier", AccessUserKey);
                jsonParam.put("secret", AccessKey);
                jsonParam.put("firstname", "User");
                jsonParam.put("lastname", "Name");
                jsonParam.put("email", emailID);
                jsonParam.put("address1", "na");
                jsonParam.put("city", "na");
                jsonParam.put("state", "na");
                jsonParam.put("postcode", "00000");
                jsonParam.put("country", "US");
                jsonParam.put("phonenumber", "0000000000");
                jsonParam.put("password2", random);
                jsonParam.put("repsonsetype", "json");

                Log.i("JSON", jsonParam.toString());
                DataOutputStream os = new DataOutputStream(conn.getOutputStream());
                os.writeBytes(URLEncoder.encode(jsonParam.toString(), "UTF-8"));
                //os.writeBytes(jsonParam.toString());

                os.flush();
                os.close();

                Log.i("STATUS", String.valueOf(conn.getResponseCode()));
                Log.i("MSG", conn.getResponseMessage());



                conn.disconnect();
            } catch (Exception e) {
                e.printStackTrace();
            }

        }
    });

    thread.start();

}

It should return "result=success".它应该返回“结果=成功”。

But actually returns "result=error;message=You did not enter your first name".但实际上返回“result=error;message=You did not enter your first name”。

It's seems your API doesn't work in this sample.看来您的 API 在此示例中不起作用。

try Postman and if json doesn't work there, issue is in your api.尝试Postman ,如果 json 在那里不起作用,则问题出在您的 api 中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM