zoukankan      html  css  js  c++  java
  • 接口实例

    package com.score;

    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStreamReader;
    import java.io.OutputStream;
    import java.net.HttpURLConnection;
    import java.net.URL;


    public class URLConnection {
    public static String GetResponse(String Info) throws IOException
    {
    String path = "http://newcrm.lietou.com/leads/leadsscore.json";

    //1, 得到URL对象
    URL url = new URL(path);

    //2, 打开连接
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    //3, 设置提交类型
    conn.setRequestMethod("POST");

    //4, 设置允许写出数据,默认是不允许 false
    conn.setDoOutput(true);
    conn.setDoInput(true);//当前的连接可以从服务器读取内容, 默认是true

    //5, 获取向服务器写出数据的流
    OutputStream os = conn.getOutputStream();
    //参数是键值队 , 不以"?"开始
    os.write(Info.getBytes());
    //os.write("googleTokenKey=&username=admin&password=5df5c29ae86331e1b5b526ad90d767e4".getBytes());
    os.flush();
    //6, 获取响应的数据
    //得到服务器写回的响应数据
    BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream(),"utf-8"));
    String str = br.readLine();

    System.out.println("响应内容为: " + str);

    return str;
    }
    public static void main(String[] args) throws IOException {
    URLConnection connection = new URLConnection();
    String Info = "source="+"13"+"&"+"callback=data";

    //String Info = "source="+"1"+"&"+"serviceType="+"1"+"&"+"companyCertificate="+"null"+"&"+"callback=data";
    System.out.println(Info);
    //String data = "{'sourceCode':1,'serviceType':1}";
    connection.GetResponse(Info);
    }
    }

  • 相关阅读:
    prototype的本质
    如何只用CSS做到完全居中
    CSS3 过渡效果触发时机的问题
    HTML转义字符
    SVG总结小知识
    JavaScript中Switch使用
    AngularJS注入依赖路由总结
    echart模块化单文件引入
    CSS定义input disabled样式
    海盗船长小米首页小船来回摆动CSS3.0效果
  • 原文地址:https://www.cnblogs.com/yuyanhzao/p/9343053.html
Copyright © 2011-2022 走看看