Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/355.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/191.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将cURL转换为改装正确的形式?_Java_Android_Url_Curl_Retrofit2 - Fatal编程技术网

Java 如何将cURL转换为改装正确的形式?

Java 如何将cURL转换为改装正确的形式?,java,android,url,curl,retrofit2,Java,Android,Url,Curl,Retrofit2,对不起我的英语。我想用这个。为确定文本的语言 请求卷曲: curl -X POST -d "outputMode=json" --data-urlencode text@ibm.txt -d "url=http://www.ibm.com/us-en/" "https://gateway-a.watsonplatform.net/calls/text/TextGetLanguage?apikey=%API_KEY%" 我使用改装的要求 public interface LanguageDete

对不起我的英语。我想用这个。为确定文本的语言

请求卷曲:

curl -X POST -d "outputMode=json" --data-urlencode text@ibm.txt -d "url=http://www.ibm.com/us-en/" "https://gateway-a.watsonplatform.net/calls/text/TextGetLanguage?apikey=%API_KEY%"
我使用改装的要求

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();
            }
        });
我在站点中生成的后模型

问题: 虽然apikey完全有效,但我没有得到任何回应。 如何在接口参数r outputMode=json中指定? 我正确地将cURL翻译成了LanguageDetectionApi?
在我看来,类语言DetectionAPI中的整个错误都是错误的。你能帮我处理这件事吗?谢谢大家!

更改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应该是唯一的主机名

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);
}