当前位置: 首页 > news >正文

网页网站开发大概多少钱应用公园制作app软件下载

网页网站开发大概多少钱,应用公园制作app软件下载,网站开发建站,为什么没人做团购网站转自#xff1a; java网络编程-HTTP编程_Stillsings的博客-CSDN博客HTTP编程Java HTTP编程支持模拟成浏览器的方式去访问网页URL, Uniform Resource Locator#xff0c;代表一个资源URLConnection获取资源连接器根据URL的openConnection#xff08;#xff09;方法获得URL…转自 java网络编程-HTTP编程_Stillsings的博客-CSDN博客HTTP编程Java HTTP编程支持模拟成浏览器的方式去访问网页URL, Uniform Resource Locator代表一个资源URLConnection获取资源连接器根据URL的openConnection方法获得URLConnectionconnect方法建立和资源的联系通道getInputStream方法获取资源的内容示例代码Get获取网页h...https://blog.csdn.net/Listen_heart/article/details/104448012 【1】HTTP编程 Java HTTP编程 支持模拟成浏览器的方式去访问网页     URL, Uniform Resource Locator代表一个资源     URLConnection         获取资源连接器         根据URL的openConnection方法获得URLConnection         connect方法建立和资源的联系通道         getInputStream方法获取资源的内容 【2】URLConnection 示例代码1Get获取网页html-使用URLConnection package com.lihuan.network.demo03;import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Map;public class URLConnectionGetTest {public static void main(String[] args) {try {String urlName http://www.baidu.com;URL url new URL(urlName);URLConnection connection url.openConnection();//建立联系通道connection.connect();//打印http的头部信息MapString, ListString headers connection.getHeaderFields();for (Map.EntryString, ListString entry : headers.entrySet()){String key entry.getKey();for (String value : entry.getValue()){System.out.println(key : value);}}//输出将要收到的内容属性信息System.out.println(-------------);System.out.println(getContentType: connection.getContentType());System.out.println(getContentLength: connection.getContentLength());System.out.println(getContentEncoding: connection.getContentEncoding());System.out.println(getDate: connection.getDate());System.out.println(getExpiration: connection.getExpiration());System.out.println(getLastModified: connection.getLastModified());System.out.println(-------------);BufferedReader br new BufferedReader(new InputStreamReader(connection.getInputStream(), StandardCharsets.UTF_8));// 输出收到的内容String line ;while ((line br.readLine()) ! null){System.out.println(line);}br.close();} catch (IOException e) {e.printStackTrace();}} } 实例代码2 Post提交表单-使用 HttpURLConnection package com.lihuan.network.demo03;import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.net.*; import java.util.HashMap; import java.util.Map; import java.util.Scanner;public class URLConnectionPostTest {public static void main(String[] args) throws IOException {String urlString https://tools.usps.com/zip-code-lookup.htm?byaddress;Object userAgent HTTPie/0.9.2;Object redirects 1;CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));MapString, String params new HashMapString, String();params.put(tAddress, 1 Market Street);params.put(tCity, san Francisco);params.put(sState, CA);String result doPost(new URL(urlString), params,userAgent null ? null : userAgent.toString(),redirects null ? -1 : Integer.parseInt(redirects.toString()));System.out.println(result);}public static String doPost(URL url, MapString, String nameValuePairs, String userAgent, int redirects) throws IOException {HttpURLConnection connection (HttpURLConnection) url.openConnection();//设置请求头if(userAgent ! null){connection.setRequestProperty(User-Agent, userAgent);}//设为不自动重定向if(redirects 0){connection.setInstanceFollowRedirects(false);}//设置可以使用conn.getOutputStream().printconnection.setDoOutput(true);//输出请求的参数try (PrintWriter out new PrintWriter(connection.getOutputStream())){boolean first true;for (Map.EntryString, String pair : nameValuePairs.entrySet()){//参数拼接if(first){first false;}else{out.print();}String name pair.getKey();String value pair.getValue();out.print(name);out.print();out.print(URLEncoder.encode(value, UTF-8));}}String encoding connection.getContentEncoding();if(encoding null){encoding UTF-8;}if(redirects 0){int responseCode connection.getResponseCode();System.out.println(responseCode: responseCode);if(responseCode HttpURLConnection.HTTP_MOVED_PERM|| responseCode HttpURLConnection.HTTP_MOVED_TEMP|| responseCode HttpURLConnection.HTTP_SEE_OTHER){String location connection.getHeaderField(Location);if(location ! null){URL base connection.getURL();connection.disconnect();return doPost(new URL(base, location), nameValuePairs, userAgent, redirects - 1);}}}else if(redirects 0){throw new IOException(Too many redirects);}//接下来获取html内容StringBuilder response new StringBuilder();try (Scanner in new Scanner(connection.getInputStream(), encoding)){while (in.hasNextLine()){response.append(in.nextLine());response.append(\n);}}catch (IOException e){InputStream err connection.getErrorStream();if(err null) throw e;try (Scanner in new Scanner(err)){response.append(in.nextLine());response.append(\n);}}return response.toString();} } 【3】JDK HttpClient JDK 9新增JDK10更新JDK11正式发     java.net.http包     取代URLConnection     支持HTTP/1.1和HTTP/2     实现大部分HTTP方法     主要类         HttpClient         HttpRequest         HttpResponse HttpComponents 是一个集成的Java HTTP工具包     实现所有HTTP方法: get/post/put/delete     支持自动转向     支持https协议     支持代理服务器等 HttpComponent示例代码3Get获取网页html package com.lihuan.network.demo04;import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.util.EntityUtils;import java.io.IOException;public class HttpComponentGetTest {public static void main(String[] args) {CloseableHttpClient httpClient HttpClients.createDefault();RequestConfig requestConfig RequestConfig.custom().setConnectTimeout(5000).setConnectionRequestTimeout(5000).setSocketTimeout(5000).setRedirectsEnabled(true).build();HttpGet httpGet new HttpGet(http://www.baidu.com);httpGet.setConfig(requestConfig);String strResult ;try {HttpResponse httpResponse httpClient.execute(httpGet);if(httpResponse.getStatusLine().getStatusCode() 200){strResult EntityUtils.toString(httpResponse.getEntity(), UTF-8);System.out.println(strResult);}else{}} catch (IOException e) {e.printStackTrace();}finally {try {httpClient.close();} catch (IOException e) {e.printStackTrace();}}} } HttpComponent实例代码4Post提交表单 package com.lihuan.network.demo04;import org.apache.http.HttpResponse; import org.apache.http.client.config.RequestConfig; import org.apache.http.client.entity.UrlEncodedFormEntity; import org.apache.http.client.methods.HttpPost; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.LaxRedirectStrategy; import org.apache.http.message.BasicNameValuePair; import org.apache.http.util.EntityUtils;import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List;public class HttpComponentsPostTest {public static void main(String[] args) throws UnsupportedEncodingException {//获取可关闭的 httpClientCloseableHttpClient httpClient HttpClientBuilder.create().setRedirectStrategy(new LaxRedirectStrategy()).build();//配置超时时间RequestConfig requestConfig RequestConfig.custom().setConnectTimeout(10000).setConnectionRequestTimeout(10000).setSocketTimeout(10000).setRedirectsEnabled(false).build();HttpPost httpPost new HttpPost(https://tools.usps.com/zip-code-lookup.htm?byaddress);//设置超时时间httpPost.setConfig(requestConfig);ListBasicNameValuePair list new ArrayList();list.add(new BasicNameValuePair(tAddress, URLEncoder.encode(1 Market Street, UTF-8)));list.add(new BasicNameValuePair(tCity, URLEncoder.encode(san Francisco, UTF-8)));list.add(new BasicNameValuePair(sState, CA));try {UrlEncodedFormEntity entity new UrlEncodedFormEntity(list, UTF-8);//设置post请求参数httpPost.setEntity(entity);httpPost.setHeader(User-Agent, HTTPie/0.9.2);HttpResponse httpResponse httpClient.execute(httpPost);String strResult ;if(httpResponse ! null){System.out.println(httpResponse.getStatusLine().getStatusCode());if(httpResponse.getStatusLine().getStatusCode() 200){strResult EntityUtils.toString(httpResponse.getEntity());}else{strResult Error Response httpResponse.getStatusLine().toString();}}else{}System.out.println(strResult);} catch (IOException e) {e.printStackTrace();} finally {if(httpClient ! null){try {httpClient.close();} catch (IOException e) {e.printStackTrace();}}}} }
http://wiki.neutronadmin.com/news/326689/

相关文章:

  • 昆明移动网站建设即墨有做网站的吗
  • asp网站变慢wordpress heroku
  • 有什么那个网站页面设计要怎么做
  • 合网站建设网站建设与优化推广方案模板
  • 2018年网站开发哪些做海报比较好的网站
  • 网站诊断书哪个网站可兼职做logo
  • 视觉差的网站wordpress建站多少钱
  • 在线企业建站服务网站开发跟app开发的差别
  • 做一般的公司网站需要多少钱外贸网站建设收益
  • 京东网站建设设计框架图公司怎么做网站推广
  • 装修公司网站 源码深圳市外贸公司
  • 孵化器网站建设方案南宁网站制作费用
  • 珠海网站推广价格北京微信网站建设公司
  • 哈尔滨住房和城乡建设厅网站html游子吟网页制作代码
  • 学做家常菜的网站武进做网站的公司
  • 免费营销型网站建设吉林市做网站
  • 申请一个网站需要怎么做看房自己的网站建设多少钱
  • 国内免费视频素材无水印素材网站网站建设需求计划
  • 建设门户网站特点cms建站程序
  • 织梦dedecms绿色led照明公司企业网站模板 下载win7优化教程
  • 做网站放广告收益北京最新进出京政策(今天)
  • 有的域名怎样做网站近期军事新闻事件
  • 有经验的佛山网站设计创业网站模板免费下载
  • 网站开发英语英语网页代码软件
  • ftp上传后没有网站新华网站建设
  • 东莞浩智建设网站公司用ps做网站导航
  • 百度做的网站 如果不做推广了 网站还保留吗国内新闻最新消息10条简短2022
  • 网站有访问量 为什么没有询盘企业微信小程序免费制作平台
  • 网站安全检测在线网站关键词优化培训
  • 安徽建设厅网站打不开大连开发区网站建设