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

网站建设的方案互联网营销推广方案

网站建设的方案,互联网营销推广方案,展厅装修设计,做一家网站的成本加哥最近做第三方接口开发,对方提供的是get方式的http请求,下面加哥给大家进行了总结如何用java代码去发送http请求并获取结果。 下面是发送get请求的工具类 1.不要求携带token的方式 public static String getUrl(String tempurl,String bm) {String…

加哥最近做第三方接口开发,对方提供的是get方式的http请求,下面加哥给大家进行了总结如何用java代码去发送http请求并获取结果。

下面是发送get请求的工具类

1.不要求携带token的方式

public static String getUrl(String tempurl,String bm) {String result="";try {URL url = new URL(tempurl);InputStream is = null;URLConnection con=url.openConnection();con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");con.setConnectTimeout(120000);con.setReadTimeout(120000);con.connect();try {is = con.getInputStream();BufferedReader reader = null;try {reader = new BufferedReader(new InputStreamReader(is,bm));String s="";String linesep = System.getProperty("line.separator");while((s = reader.readLine())!=null){result += s+linesep ;}reader.close();} catch (Exception e) {e.printStackTrace();}finally {if (reader != null) {try {reader.close();} catch (Exception e1) {}}}is.close();}catch (FileNotFoundException e2) {;}} catch (Exception e1) {e1.printStackTrace();}return result;}

下面是使用封装的好的请求工具类发送请求

public static void main(String[] args) {String str = "http://110.43.47.12:8089/system/sim?population=5&iteration=2&prediction=5&timestep=1&density=1";String sql=Get.getUrl(str,"utf-8");System.out.println(sql);}

注意请求发送后返回来的是JSON字符串,大家对其进行解析获取自己需要的数据即可。此外,还需注意第二个参数是编码格式。

2.要求携带token的方式

public static String getpage(String tempurl,String bm,String token ) {
        String result="";
        try {
            URL url = new URL(tempurl);
            InputStream is = null;
            URLConnection con=url.openConnection();
            con.addRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
            con.setConnectTimeout(120000);
            con.setReadTimeout(120000);
            con.addRequestProperty("x-access-token",token);
            con.connect();
            try {
                is = con.getInputStream();
                BufferedReader reader = null;
                try {
                    reader = new BufferedReader(new InputStreamReader(is,bm));
                    String s="";
                    String linesep = System.getProperty("line.separator");
                    while((s = reader.readLine())!=null){
                        result += s+linesep ;
                    }
                    reader.close();
                } catch (Exception e) {
                    e.printStackTrace();
                }finally {
                    if (reader != null) {
                        try {
                            reader.close();
                        } catch (Exception e1) {
                        }
                    }
                }
                is.close();
            }catch (FileNotFoundException e2) {
                ;
            }
        } catch (Exception e1) {
            e1.printStackTrace();
        }
        return result;
    }

http://www.rdtb.cn/news/19120.html

相关文章:

  • 网站logo位置网络营销策略方案
  • 做购物类网站有哪些网络工程师培训班要多少钱
  • 网站建设与管理案例...百度搜索推广登录入口
  • 做网站原型的简单工具网络竞价
  • 计量检测网站平台建设方案营销存在的问题及改进
  • 深圳做网站的网络公司百度知道首页
  • 网站开发与客户交流seo推广优化工具
  • 织梦网站怎么做索引地图seo网站分析报告
  • 网页设计报价表杭州优化公司多少钱
  • 怎么在国外网站做推广上海城市分站seo
  • 罗定市住房和城乡建设局网站推广关键词如何优化
  • 政府网站建设目的创新驱动发展战略
  • 高中男女做那个视频网站5g站长工具seo综合查询
  • 中小企业管理培训班seo网站平台
  • 网站建设增值税发票seo实战培训课程
  • 帮客户做违法网站违法么培训公司排名
  • 文员做任务赚钱的网站大数据统计网站
  • c 做的网站网络推广的公司是骗局吗
  • 安卓开发为什么不火了天津百度seo
  • 靠谱的建站团队精准营销的案例
  • 德州 网站建设seo整站优化外包公司
  • 乐辰科技网站建设众志seo
  • 做珠宝建个网站推广怎么样免费站推广网站2022
  • wordpress 去掉主题seo难不难
  • wordpress订单管理插件北京seo平台
  • b2b网站排行怎么推广平台
  • 百度电商广告代运营东莞优化seo
  • 男女做污的事情网站网站交易
  • 商贸公司寮步网站建设泰州百度公司代理商
  • 杭州外贸建站搜索引擎营销优化策略有哪些