简体   繁体   English

HttpClient执行时出现org.apache.http.client.ClientProtocolException

[英]org.apache.http.client.ClientProtocolException appears when HttpClient executes

I want to send to server some data via POST-request. 我想通过POST请求向服务器发送一些数据。 My code: 我的代码:

protected Void doInBackground(Void... arg)
        {       
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost post = new HttpPost("https://money.yandex.ru/oauth/authorize");

            post.addHeader("Host", "m.sp-money.yandex.ru");
            post.addHeader("Content-Type", "application/x-www-form-urlencoded");
            post.addHeader("Content-Length", "154");

            //data back from server
            String responseBackFromServer = "";

            try 
            {
                List<NameValuePair> pairs = new ArrayList<NameValuePair>();
                pairs.add(new BasicNameValuePair("client_id", "51"));
                pairs.add(new BasicNameValuePair("response_type", "code"));
                pairs.add(new BasicNameValuePair("redirect_uri", "https://vk.com/"));
                pairs.add(new BasicNameValuePair("scope", "account-info"));

                post.setEntity(new UrlEncodedFormEntity(pairs));
                HttpResponse server_response = httpclient.execute(post);//!!!exception is appearing here!!!

                responseBackFromServer = EntityUtils.toString(server_response.getEntity());

            }
            catch (ClientProtocolException e) 
            {
                e.printStackTrace();
                Log.d(LOG_TAG, "" + e);
            }
}

But on "HttpResponse server_response = httpclient.execute(post);" 但是在“ HttpResponse server_response = httpclient.execute(post);”上 string ClientProtocolException appears. 出现字符串ClientProtocolException。 How can I fix it? 我该如何解决?

Try removing all the addHeader statements. 尝试删除所有的addHeader语句。 The framework should add them for you. 该框架应为您添加它们。

See here for an example: https://hc.apache.org/httpcomponents-client-4.3.x/quickstart.html 参见此处的示例: https : //hc.apache.org/httpcomponents-client-4.3.x/quickstart.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 org.apache.http.client.ClientProtocolException - org.apache.http.client.ClientProtocolException HttpPost 中的 org.apache.http.client.ClientProtocolException - org.apache.http.client.ClientProtocolException in HttpPost 使用httpclient 4.1.2连接到https会产生org.apache.http.client.ClientProtocolException - connection to https with httpclient 4.1.2 gives org.apache.http.client.ClientProtocolException Apache HttpComponents:org.apache.http.client.ClientProtocolException - Apache HttpComponents: org.apache.http.client.ClientProtocolException 调用AlchemyAPI时获取org.apache.http.client.ClientProtocolException - Getting org.apache.http.client.ClientProtocolException while calling AlchemyAPI Unirest Java 客户端:kong.unirest.UnirestException:org.apache.http.client.ClientProtocolException - Unirest Java Client : kong.unirest.UnirestException: org.apache.http.client.ClientProtocolException Spring WS-I / O错误:null; 嵌套的异常是org.apache.http.client.ClientProtocolException - Spring WS - I/O error: null; nested exception is org.apache.http.client.ClientProtocolException java.lang.NoClassDefFoundError:使用jsonparser()时org / apache / http / client / ClientProtocolException - java.lang.NoClassDefFoundError: org/apache/http/client/ClientProtocolException while using the jsonparser() 如何关闭 org.apache.http.client.HttpClient 对象的连接 - How to close connection of org.apache.http.client.HttpClient object org.apache.http.client.httpclient是抽象实例,无法实例化 - org.apache.http.client.httpclient is abstract cannot be instantiated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM