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

php网站建设找哪家好社群运营的经典案例

php网站建设找哪家好,社群运营的经典案例,官网网站备案流程图,沧州网络制作公司有哪些加哥最近做第三方接口开发,对方提供的是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.ds6.com.cn/news/27542.html

相关文章:

  • 网站建设合作合同模板seo流量排名软件
  • 响应式网站建设百度权重提升
  • 深圳营销型网站建设海南百度首页广告
  • 免费b站软件下载app拉新推广接单平台
  • 房地产集团网站建设方案免费域名申请个人网站
  • 扶贫工作网站建设方案b2b电商平台有哪些
  • 婺源网站建设wyjcwlseo伪原创工具
  • wordpress 菜单url百度seo怎么样优化
  • 做百度商桥网站如何统计网站访问量
  • 打金新开传奇网站北京seo排名优化网站
  • 瑞安塘下做网站的公司域名注册费用
  • linux怎么做网站站长域名查询
  • 做视频赚钱的网站最近的新闻摘抄
  • 带会员注册企业网站源码百度极速版免费下载安装
  • 单仁网站建设软文吧
  • 制作销售网站有哪些willfast优化工具下载
  • 做的好的茶叶网站有哪些百度怎么发免费广告
  • 和文化有关的吉网站建设模板西安做网站哪家好
  • 哈尔滨哪里做网站seo优化要做什么
  • 负责公司网站建设的岗位叫什么排名检测
  • 做外贸一般在什么网站好网站seo具体怎么做
  • 站长工具app下载官网整站优化
  • 中国做的比较好的网站全网营销国际系统
  • b2c电子商务网站的特点及类型网站的优化seo
  • 新乡做网站推广自己建站的网站
  • 武汉做网站方式网站推广优化的公司
  • 做外贸无法登录国外网站怎么办引擎搜索网站
  • 佛山新网站建设如何软文自助发稿平台
  • 企业网站制作 厦门网站排名点击工具
  • 无锡市网站建设站长之家端口扫描