Android HttpsURLConnection setDoOutput(true)不是';行不通

Android HttpsURLConnection setDoOutput(true)不是';行不通,android,http,twitter,https,httpsurlconnection,Android,Http,Twitter,Https,Httpsurlconnection,因此,我目前正在编写一个android应用程序,它将使用Twitter的1.1从特定用户那里获取推文,这需要一个POST HTTP请求来获取承载令牌。我设置了一个方法,使用HttpsURLConnection打开连接,但是 conn.setDoOutput(真)方法不起作用 conn.doOutput保持false 请求保持默认的GET 我做错什么了吗 在AsyncTask的doInBackground()方法中调用此方法: public String getRequestBearerTok

因此,我目前正在编写一个android应用程序,它将使用Twitter的1.1从特定用户那里获取推文,这需要一个POST HTTP请求来获取承载令牌。我设置了一个方法,使用
HttpsURLConnection
打开连接,但是

  • conn.setDoOutput(真)方法不起作用
  • conn.doOutput
    保持
    false
  • 请求保持默认的
    GET
我做错什么了吗

AsyncTask
doInBackground()
方法中调用此方法:

public String getRequestBearerToken(String endUrl) throws IOException {
    String encodedCred = encodeKeys("API-key", "API-secret");
    HttpsURLConnection connection = null;
    try {
        URL url = new URL(endUrl);
        connection = (HttpsURLConnection) url.openConnection();

        connection.setInstanceFollowRedirects(false);
        connection.setDoInput(true);
        connection.setDoOutput(true);

        connection.setRequestMethod("POST");


            // POST request properties
            connection.setRequestProperty("Host", "api.twitter.com");
            connection.setRequestProperty("User-Agent", getResources()
                    .getString(R.string.app_name));
            connection.setRequestProperty("Authorization", "Basic "
                    + encodedCred);
            connection.setRequestProperty("Content-Type",
                    "application/x-www-form-urlencoded;charset=UTF-8");
            connection.setRequestProperty("Content-Length", "29");
            connection.setUseCaches(false);

            ...

为RESTAPI使用volley库非常简单且高效。我正在使用截击库进行发帖请求。我知道如何设置参数,但如何设置主请求体?只需将请求放入一个方法中,并在必要时调用它,然后在活动/类中创建一个变量RequestQueue。在oncreate或classc构造函数中,将其设置为requestQueue=Volley.newRequestQueue(ctx);(这就是您所说的主请求对吗)?这也很有帮助,但我想知道在哪里设置HTTP请求的主体。这和标题是分开的。是的,出于某种原因,截击库不适合我。有人知道最初的问题吗?