Post方法不更新服务器上的数据

时间:2013-10-16 05:33:36

标签: java android

我正在尝试在服务器上发布数据和更新数据。在发布时,我收到响应成功,但此数据未在给定URL上更新。请建议我这些数据如何反映给定的URL。

public static ServerResponse postData(String url,
        FarmInchargeEntity farmInchargeEnt) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost(url);
    ServerResponse sr = new ServerResponse();
    farmChargeEntity = farmInchargeEnt;

    try {

        StringEntity se;
        se = new StringEntity(getRequestJson());

        // Set HTTP parameters
        httppost.setEntity(se);
        httppost.setHeader("Accept", "application/json");
        httppost.setHeader("Content-type", "application/json;charset=UTF-8");
        httppost.setHeader("Accept-Encoding", "gzip");

        // Execute HTTP Post Request
        HttpResponse response = httpclient.execute(httppost);

        if (response.getStatusLine().getStatusCode() == 200) {
            sr.setSuccess(true);
            sr.setResponseString(response.toString());
        } else {
            sr.setErrorMessage(response.toString());
        }

        Log.v("HttpPostResponse", "" + response.toString());

    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return sr;
}

//获取JSON字符串的方法

public static String getRequestJson() {
    String r = "{" + "id" + ":" + null + "," + "surName" + ":"
            + farmChargeEntity.surName + "," + "givenName" + ":"
            + farmChargeEntity.givenName + "," + "dateOfBirth" + ":"
            + farmChargeEntity.dateOfBirth + "," + "education" + ":" + null
            + "," + "gender" + ":" + farmChargeEntity.gender + ","
            + "address" + ":" + "{" + "id" + ":" + null + "," + "addrLine1"
            + ":" + farmChargeEntity.addrLine1 + "," + "addrLine2" + ":"
            + farmChargeEntity.addrLine2 + "," + "taluk" + ":"
            + farmChargeEntity.taluk + "," + "district" + ":"
            + farmChargeEntity.district + "," + "state" + ":"
            + farmChargeEntity.state + "," + "pincode" + ":"
            + farmChargeEntity.pinCode + "," + "phoneNumber" + ":"
            + farmChargeEntity.phoneNumber + "," + "mobileNumber" + ":"
            + farmChargeEntity.mobileNumber + "," + "email" + ":"
            + farmChargeEntity.email + "," + "fax" + ":"
            + farmChargeEntity.fax + "," + "longitude" + ":"
            + farmChargeEntity.longitude + "," + "latitude" + ":"
            + farmChargeEntity.latitude + "," + "radius" + ":"
            + farmChargeEntity.radius + "}" + "," + "familyMembers" + ":"
            + farmChargeEntity.familyNumbers + "," + "startDateOfAssoc"
            + ":" + farmChargeEntity.startDateOfAssoc + ","
            + "endDateOfAssoc" + ":" + farmChargeEntity.endDateOfAssoc
            + "," + "farm" + ":" + farmChargeEntity.farmInchargeId + "}";

    return r;

}

1 个答案:

答案 0 :(得分:0)

我认为在你身边它的罚款可能只是在服务器端检查一次,因为当你发布数据然后服务器接收数据并发送响应成功但之后我将存储在数据库中或不只是在你的网络端检查一次服务器代码