网站开发时间,seo优化包括哪些内容,怎么建设商业网站,做网站ddos攻击#xff0c;在JAVA中进行网络通信#xff0c;我们需要定义一个HttpPost对象#xff0c;此对象需要输入url参数。然后定义一个ListNameValuePair对象来以JSON的形式存储数据。接着通过HttpPost的getParams().setParameter()方法进行一些必要参数的设置#xff0c;例…在JAVA中进行网络通信我们需要定义一个HttpPost对象此对象需要输入url参数。然后定义一个ListNameValuePair对象来以JSON的形式存储数据。接着通过HttpPost的getParams().setParameter()方法进行一些必要参数的设置例如连接超时的时间与接收数据超时的时间。然后通过HttpResponse httpResponse new DefaultHttpClient().execute(request); 语句来发送Http请求并获取服务器端传来的数据。此时的数据为String类型需要吧它转换成JSONObject以便后面的分析数据与获取我们需要的数据。 网络通讯关键代码 HttpPost request new HttpPost(url);ListNameValuePair params new ArrayListNameValuePair();params.add(new BasicNameValuePair(username,I am username);params.add(new BasicNameValuePair(password, I am password);params.add(new BasicNameValuePair(verName, verName));request.getParams().setParameter( CoreConnectionPNames.CONNECTION_TIMEOUT, 10000);request.getParams().setParameter( CoreConnectionPNames.SO_TIMEOUT, 10000);request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));HttpResponse httpResponse new DefaultHttpClient() .execute(request);String retSrc EntityUtils.toString(httpResponse .getEntity());JSONObject result new JSONObject(retSrc);