如何在java中实例化类型

Dn Yk
package crawler;

import org.apache.http.client.*;
import org.apache.http.client.methods.*;

class Crawler{

    public static void main(String args[]){

    HttpClient httpclient = new HttpClient();     // **HERE!!!!!!!!!**

    GetMethod getMethod = new GetMethod("http://www.google.com");

    int statusCode = httpclient.executeMethod(getMethod);

    System.out.println("response=" + getMethod.getResponseBodyAsString());;

    getMethod.releaseConnection();

    }

}

来自 Apache Httpclient 的 HttpClient。

编码:

@SuppressWarnings("deprecation")
public interface HttpClient 

如何解决问题“ HttpClient httpclient = new HttpClient();”?谢谢!

苏雷什·阿塔

HttpClient是一个接口。YTou不能这样做。

正确的做法是

HttpClient client = HttpClientBuilder.create().build();

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章