見各種。如圖所示的cookies
導入Java . io . buffered reader;
導入Java . io . io exception;
導入Java . io . inputstream;
導入Java . io . inputstreamreader;
導入Java . io . output stream;
導入Java . io . output streamwriter;
導入Java . net . httpurl connection;
導入Java . net . malformedurexception;
導入Java . net . URL;
導入Java . net . URL connection;
導入Java . util . concurrent . executorservice;
導入Java . util . concurrent . executors;
導入Java . util . concurrent . time unit;
導入com . cookies . del cookies . threada;
公共類HttpGetRequest
{
公共靜態void doPost()拋出IOException
{
String參數= " commentid = & amp內容=HTTP測試& ampreplyId = ";
URL url =新URL("ment/submit?id = 50440123”);
URL connection connection = URL . open connection();
HttpURLConnection ");
/u 013256816/article/details/50440123”);
httpurlconnection . setrequestproperty("用戶代理"," Mozilla/5.0(Windows NT 6.1;WOW64) AppleWebKit/537.36 (KHTML,像壁虎)Chrome/46 . 0 . 2490 . 71 Safari/537.36”);
OutputStream outputStream = null
output streamwriter output streamwriter = null;
InputStream inputStream = null
InputStreamReader InputStreamReader = null;
BufferedReader reader = null
string buffer result buffer = new string buffer();
String tempLine = null
嘗試{
output stream = httpurlconnection . get output stream();
output streamwriter = new output streamwriter(output stream);
output streamwriter . write(parameter data . tostring());
output streamwriter . flush();
system . out . println(httpurlconnection . getresponsecode());
inputStream = httpurlconnection . getinputstream();
inputStreamReader = new inputStreamReader(inputStream);
reader = new buffered reader(inputStreamReader);
while((tempLine = reader . readline())!= null) {
result buffer . append(tempLine);
}
}最後{
if (outputStreamWriter!= null) {
output streamwriter . close();
}
if (outputStream!= null) {
output stream . close();
}
如果(讀者!= null) {
reader . close();
}
if (inputStreamReader!= null) {
inputstreamreader . close();
}
if (inputStream!= null) {
inputstream . close();
}
}
system . out . println(result buffer . tostring());
}
靜態類ThreadA實現Runnable{
int sleepTime
公共線程A(int sleepTime)
{
this . sleep time = sleep time;
}
@覆蓋
公共無效運行()
{
while(真)
{
嘗試
{
doPost();
}
catch (IOException e1)
{
e 1 . printstacktrace();
}
嘗試
{
時間單位。毫秒.睡眠(this . sleep time);
}
catch(中斷異常e)
{
e . printstacktrace();
system . out . println(thread . current thread()。getName()+"已停止!");
打破;
}
}
}
}
公共靜態void main(String[] args)引發IOException
{
ExecutorService exec = executors . newcachedthreadpool();
for(int I = 0;我& ltRuntime.getRuntime()。available processors();i++)
{
Thread Thread = new Thread(new ThreadA(1000));
exec.execute(線程);
}
exec . shut down();
}
}
用自己的cookie替換上面的cookie可以添加評論,用別人的cookie替換也可以增加csdn的點數。