我在 .net 中的代码如下所示。我想用java写它。我该怎么做?我应该使用 httpclient 还是 socket 来做到这一点?
using (WebClient wc = new WebClient())
{
wc.Encoding = System.Text.Encoding.UTF8;
wc.Headers.Add("HOST", "example.com");
wc.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:16.0) Gecko/20100101 Firefox/16.0");
wc.Headers.Add("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
wc.Headers.Add("Accept-Language", "tr-TR,tr;q=0.8,en-US;q=0.5,en;q=0.3");
html = wc.DownloadString(link);
if (temp == null)
return string.Empty;
return html;
}