我想与我自己的servlet建立一个Http连接.这是我的代码:
try
{
HttpClient client = new DefaultHttpClient();
HttpPost httpMethod = new HttpPost("http://localhost:8080/getHeader/HeaderServlet");
httppost.setHeader("Content-Type", "application/x-www-form-urlencoded");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = client.execute(httppost, responseHandler);
String result = response.toString();
}
Run Code Online (Sandbox Code Playgroud)
但我无法,我得到错误:
org.apache.http.conn.HttpHostConnectionException:Connection to http://localhost:8080 refused
Run Code Online (Sandbox Code Playgroud)
我将感谢你的帮助
我想做一个Htttp连接这是我的代码
try
{
HttpClient client = new DefaultHttpClient();
HttpPost httpMethod = new HttpPost("http://www.google.co.in/");
String requestBody = "some text";
HttpMethod.setEntity(new StringEntity(requestBody));
HttpResponse response = client.execute(httpMethod);
textView.setText(response.getStatusLine().toString());
}
Run Code Online (Sandbox Code Playgroud)
但我无法得到"HTTP/1.0 405方法不允许"错误,我将感谢你的帮助
我正在使用以下代码建立http连接:
HttpClient client = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
HttpResponse response = client.execute(httpPost);
Run Code Online (Sandbox Code Playgroud)
我想从响应对象中读取一个bytearray.
我该怎么办?