2017-03-24 9 views
0

が、これは私のクラスのSERVERTIMEです:レトロフィット2.2エラーURLのAndroidメーカー

public class ServerTime { 

@SerializedName("time") 
private String time; 
@SerializedName("date") 
private String date; 
@SerializedName("milliseconds_since_epoch") 
private String milliSeconds; 

public String getTime() { 
    return time; 
} 

public void setTime(String time) { 
    this.time = time; 
} 

public String getDate() { 
    return date; 
} 

public void setDate(String date) { 
    this.date = date; 
} 

public String getMilliSeconds() { 
    return milliSeconds; 
} 

public void setMilliSeconds(String milliSeconds) { 
    this.milliSeconds = milliSeconds; 
} 
} 

マイインタフェース:

public interface Api { 
@GET("/") 
public Call<ServerTime> getServerTime(); 
} 

そして、私の方法は次のとおりです。

void fetchTime2() { 
    Retrofit retrofit = new Retrofit.Builder() 
      .baseUrl("http://luisbaltodano.pe.hu/Galeria/Time.php/")     
      .addConverterFactory(GsonConverterFactory.create()) 
      .build(); 
    Api api = retrofit.create(Api.class); 
    Call<ServerTime> serverTimeCall = api.getServerTime(); 
    serverTimeCall.enqueue(new Callback<ServerTime>() { 
     @Override 
     public void onResponse(Call<ServerTime> call, Response<ServerTime> response) { 
      ServerTime serverTime = response.body(); 
      tvNombre.setText("Date: " + serverTime.getDate()); 
      tvCelular.setText("Time: " + serverTime.getTime()); 
     } 

     @Override 
     public void onFailure(Call<ServerTime> call, Throwable t) { 
      Toast.makeText(getApplicationContext(), "Error while fetching time", Toast.LENGTH_SHORT).show(); 
     } 
    }); 
} 

実行すると、onFailureメソッドでトーストのみが表示されます。

私はBASEURLを変更すると今、:完璧

.baseUrl("http://date.jsontest.com/") 

この作品を...私を助け

してください:(..のURLをチェックしてください:

http://luisbaltodano.pe.hu/Galeria/Time.php/

http://date.jsontest.com/

答えて

0

バックエンド部分:http://luisbaltodano.pe.hu/Galeria/Time.php/は、次のヘッダーでjsonコンテンツを返す必要があります。Content-Type:application/json;。今度はtext/htmlを返します。

+0

ありがとう、どうすればポイントをあげることができますか?私はスタックで新しいです! –