2015-06-17 27 views
0

也許這是一個愚蠢的問題,但我已經在這一段時間stucked。我正在實施restApi的一些方法。我正在使用改造,我試圖更新客戶端信息。要進行更新,我使用了PUT方法,但我不知道爲什麼我總是得到301代碼,但我無法更新信息。這是我的代碼,謝謝你的一切。改裝更新類PUT錯誤代碼301

public interface ClientInterface { 

    @GET("/clients/{clientParam}") 
    public Client fetchClient(@Path("clientParam") String client); 

    @GET("/clients/") 
    public void fetchAllClients(Callback<List<Client>> callback); 

    @POST("/clients/") 
    public void newClient(@Body Client client, Callback<Client> callback); 

    @PUT("/clients/{clientParam}/") 
    public void updateClient(@Path("clientParam") String cod, @Body Client client,Callback<Client> callback); 
} 

後,我用更新的方法以下列方式

RestAdapter restAdapter = new RestAdapter.Builder().setEndpoint(Utils.getURLPreferences(DatosClienteActivity.this)).build(); 
ClientInterface clientRestInter = restAdapter.create(ClientInterface.class); 
Client clientsUpdate = new Client(); 

    //Fetch data into clientsUpdate object 

    clientRestInter.updateClient(codClient, clientsUpdate, new Callback<Client>() { 

     @Override 
     public void success(Client client, retrofit.client.Response response) { 

     } 

     @Override 
     public void failure(RetrofitError error) { 
      error.printStackTrace(); 
     } 
    }); 

編輯: 如果我使用凌空反對它的正常使用同一網址...

RequestQueue queue = Volley.newRequestQueue(this); 

    final JSONObject jsonObject = new JSONObject(); 
    try { 
     //Construct jsonObject 
    } catch (JSONException e) { 
     e.printStackTrace(); 
    } 

    JsonObjectRequest req = new JsonObjectRequest(Request.Method.PUT, URL, jsonObject, 
      new Response.Listener<JSONObject>() { 
       @Override 
       public void onResponse(JSONObject response) { 
        try { 
         VolleyLog.v("Response:%n %s", response.toString(4)); 
        } catch (JSONException e) { 
         e.printStackTrace(); 
        } 
       } 
      }, new Response.ErrorListener() { 
     @Override 
     public void onErrorResponse(VolleyError error) { 
      VolleyLog.e("Error: ", error.getMessage()); 
      error.printStackTrace(); 
     } 
    }); 
    queue.add(req); 

回答

0

最後我解決了它。

問題是我們有兩個不同的客戶端對象,而您獲取的對象是您必須更改並使用它來上傳PUT的對象。

我希望這有助於某人。