2017-03-11 2 views
0

私の英語は申し訳ありません。私はこれを使用したいservice。テキストの言語を決定するため。cURLを正しい形式に換装するにはどうすればいいですか?

要求(カール):

curl -X POST -d "outputMode=json" --data-urlencode [email protected] -d "url=http://www.ibm.com/us-en/" "https://gateway-a.watsonplatform.net/calls/text/TextGetLanguage?apikey=%API_KEY%" 

私は要求のためのレトロフィットを使用しています。

public class App extends Application { 

    private static LanguageDetectionApi _languageDetectionApi; 
    private Retrofit _retrofit; 

    @Override 
    public void onCreate() { 
     super.onCreate(); 

     _retrofit = new Retrofit.Builder() 
       .baseUrl(_languageDetectionApi.ROOT_URL) 
       .addConverterFactory(GsonConverterFactory.create()) 
       .build(); 
     _languageDetectionApi = _retrofit.create(LanguageDetectionApi.class); 
    } 


    public static LanguageDetectionApi getLanguageDetectionApi() { 
     return _languageDetectionApi; 
    } 
} 

をし、要求を送信します:

public interface LanguageDetectionApi { 
    public static final String ROOT_URL = "https://gateway-a.watsonplatform.net/calls/"; 

    @POST("/text/TextGetLanguage") 
    Call<List<PostModel>> getData(@Query("apikey") String apikey, @Query("text") String text); 
} 

改造オブジェクトを作成します

App app = new App(); 
     app.onCreate(); 

     app.getLanguageDetectionApi().getData("4978e60252ae102dfe1341146bb8cc3ec4bbbd78", textForRecognition).enqueue(new Callback<List<PostModel>>() { 
      @Override 
      public void onResponse(Call<List<PostModel>> call, Response<List<PostModel>> response) { 
       List<PostModel> posts = new ArrayList<>(); 
       posts.addAll(response.body()); 
      } 

      @Override 
      public void onFailure(Call<List<PostModel>> call, Throwable t) { 
       Toast.makeText(MainActivity.this, "An error occurred during networking", Toast.LENGTH_SHORT).show(); 
      } 
     }); 

PostModel iはサイトhttp://www.jsonschema2pojo.org/で生成されました。

質問: apikeyは正確に有効ですが、私には何の反応もありません。 インタフェースパラメータ "outputMode = json"の指定方法は? そして、私はLanguageDetectionApiにcURLを正しく翻訳しましたか? LanguageDetectionApiクラスの間違いが全体的に間違っているようです。これに対処できますか?ありがとうございました!以下のような

答えて

1

変更URLコード:

public interface LanguageDetectionApi { 
    public static final String ROOT_URL = "https://gateway-a.watsonplatform.net"; 

    @POST("/calls/text/TextGetLanguage") 
    Call<List<PostModel>> getData(@Query("apikey") String apikey, @Query("text") String text); 
} 

ベースURLはONYホスト名でなければなりません。

関連する問題