Java 如何从android应用程序向WHMCS安装发送正确的post请求?
我正试图通过我的android应用程序向我的WHMCS安装发送AddClient post请求,但它不断返回“结果=错误;消息=你没有输入你的名字” 我让它成功地进行了身份验证,但它似乎没有发布我正在发送的jsonObject 以下是WHMCS api文档的链接: 它应该返回“result=success”Java 如何从android应用程序向WHMCS安装发送正确的post请求?,java,android,http,request,whmcs,Java,Android,Http,Request,Whmcs,我正试图通过我的android应用程序向我的WHMCS安装发送AddClient post请求,但它不断返回“结果=错误;消息=你没有输入你的名字” 我让它成功地进行了身份验证,但它似乎没有发布我正在发送的jsonObject 以下是WHMCS api文档的链接: 它应该返回“result=success” 但实际上返回“result=error;message=You未输入您的名字”。您的API在本示例中似乎不起作用 尝试一下,若json在那个里不起作用,那个么问题就在你们的api中 publ
但实际上返回“result=error;message=You未输入您的名字”。您的API在本示例中似乎不起作用 尝试一下,若json在那个里不起作用,那个么问题就在你们的api中
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();
}