2013-10-16 59 views
0

我想發佈數據並更新服務器上的數據。發佈時,我獲得了成功的響應,但此數據未在給定的URL上更新。請告訴我這些數據將如何反映給定的URL。Post方法在不更新服務器上的數據

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; 

} 

回答

0

我想在你身邊的罰款可能只是檢查服務器端的一個時間,因爲當您發佈數據,那麼服務器接收數據併發送響應成功但之後,我會存儲在數據庫中或不只是檢查一次在您的網頁服務器代碼

相關問題