/*
* Copyright 2018 textile.com All right reserved. This software is the
* confidential and proprietary information of textile.com ("Confidential
* Information"). You shall not disclose such Confidential Information and shall
* use it only in accordance with the terms of the license agreement you entered
* into with textile.com.
*/
package com.bxm.advertisercms; import java.io.DataInputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map; /**
* @fileName com.bxm.advertisercmsaaa.java
* @CopyRright (c) 2017-bxm:杭州微财科技有限公司
* @date 2018年3月9日 上午10:40:36
* @author chzq
*/
public class Test { /**
* @date 2018年3月9日 上午10:40:40
* @param args
* @author chzq
*/
public static void main(String[] args) throws Exception {
StringBuilder sb = new StringBuilder(
"https://buy.bianxianmao.com/shop/countInfo");
Map<String, String> params = new HashMap<String, String>();
params.put("bxm_id", "前端传过来的bxm_de的值");
params.put("status","");//固定值
params.put("modeltype", "");//固定值
String result1 = GetPostUrl(sb.toString(), params, "GET",null, , );
System.out.println(result1); } public static String GetPostUrl(String sendUrl, Map<String, String> params, String sendType, String charset,
int repeat_request_count, int repeat_request_max_count) {
URL url = null;
HttpURLConnection httpurlconnection = null; try {
// 构建请求参数
StringBuffer paramSb = new StringBuffer();
if (params != null) {
for (java.util.Map.Entry<String, String> e : params.entrySet()) {
paramSb.append(e.getKey());
paramSb.append("=");
// 将参数值urlEncode编码,防止传递中乱码
paramSb.append(URLEncoder.encode(e.getValue(), "UTF-8"));
paramSb.append("&");
}
paramSb.substring(, paramSb.length() - );
}
url = new URL(sendUrl + "?" + paramSb.toString());
httpurlconnection = (HttpURLConnection) url.openConnection();
httpurlconnection.setRequestMethod("GET");
httpurlconnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpurlconnection.setDoInput(true);
httpurlconnection.setDoOutput(true); // 设置http请求超时时间30000毫秒(30秒)
httpurlconnection.setConnectTimeout();
httpurlconnection.setReadTimeout();
httpurlconnection.setUseCaches(true);
/*
* if (submitMethod.equalsIgnoreCase("POST")) {
* httpurlconnection.getOutputStream().write(postData.getBytes("GBK"
* )); httpurlconnection.getOutputStream().flush();
* httpurlconnection.getOutputStream().close(); }
*/ int code = httpurlconnection.getResponseCode();
if (code == ) {
DataInputStream in = new DataInputStream(httpurlconnection.getInputStream());
int len = in.available();
byte[] by = new byte[len];
in.readFully(by);
String rev = new String(by, "UTF-8"); in.close(); return rev;
} else {
// http 请求返回非 200状态时处理
return "<?xml version=\"1.0\" encoding=\"utf-8\" ?><error>发送第三方请求失败</error>";
} } catch (Exception e) {
e.printStackTrace();
} finally {
if (httpurlconnection != null) {
httpurlconnection.disconnect();
}
}
return null;
} }

java 调用 api接口的更多相关文章

  1. Java 调用http接口(基于OkHttp的Http工具类方法示例)

    目录 Java 调用http接口(基于OkHttp的Http工具类方法示例) OkHttp3 MAVEN依赖 Http get操作示例 Http Post操作示例 Http 超时控制 工具类示例 Ja ...

  2. Java调用webservice接口方法

                             java调用webservice接口   webservice的 发布一般都是使用WSDL(web service descriptive langu ...

  3. C#使用windows服务定时调用api接口

    使用VS创建windows服务项目: 创建好项目  会出现一个设计界面 右键弹出对话框 选择添加安装程序 名字什么的自己可以改: 项目目录: 打开项目中的ProjectInstaller.Design ...

  4. Python调用API接口的几种方式 数据库 脚本

    Python调用API接口的几种方式 2018-01-08 gaoeb97nd... 转自 one_day_day... 修改 微信分享: 相信做过自动化运维的同学都用过API接口来完成某些动作.AP ...

  5. Python调用API接口的几种方式

    Python调用API接口的几种方式 相信做过自动化运维的同学都用过API接口来完成某些动作.API是一套成熟系统所必需的接口,可以被其他系统或脚本来调用,这也是自动化运维的必修课. 本文主要介绍py ...

  6. 调用API接口,查询手机号码归属地(3)

    从mysql数据库获取电话号码,查询归属地并插入到数据库 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib, sys, pym ...

  7. 调用API接口,查询手机号码归属地(2)

    使用pymysql pip install pymysql 创建mysql测试表 CREATE TABLE `userinfo` ( `id` int(20) NOT NULL AUTO_INCREM ...

  8. 调用API接口,查询手机号码归属地(1)

    使用https://www.juhe.cn/提供的接口,查询归属地 在官网注册key即可使用. 代码如下 #!/usr/bin/python # -*- coding: utf-8 -*- impor ...

  9. (二)通过JAVA调用SAP接口 (增加一二级参数)

    (二)通过JAVA调用SAP接口 (增加一二级参数) 一.建立sap连接 请参考我的上一篇博客 JAVA连接SAP 二.测试项目环境准备 在上一篇操作下已经建好的环境后,在上面的基础上新增类即可 三. ...

随机推荐

  1. STM32F401 外部中断误触发问题

    现象:调试STM32F411低功耗的时候,使用的PA1做个唤醒源,发现在没有触发EXTI的时候,MCU居然被唤醒. 原因:PA1配置成EXTI(上拉输入),经常被误触发 解决方式:将PA1配置成浮空输 ...

  2. jquery中checkbox的选中,反选,全不选 注意1.6版本以上将attr改成prop

    <script type="text/javascript"> $(function () { // 全选 $("#btnCheckAll").bi ...

  3. spring 自定参数解析器(HandlerMethodArgumentResolver)

    https://blog.csdn.net/u010187242/article/details/73647670

  4. Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.4.1:clean (default-clean) on project

    在maven项目中 启动了2个tomcat,只能启动一个.

  5. PHP 浮点型转整型的一个奇怪现象

    起因 最近通过一个学长的题了解php弱类型的时候,发现了一个奇怪的现象. 正文 主要问题在这样一段代码: $c=(int)((0.1+$b)*10); 当$b=0.6,0.8以及其他值的时候都正常 将 ...

  6. npm 离线安装依赖

    现实场景:一台自己的电脑可以连外网,一台开发机不能连网,开发机需要安装node_modules 依赖解决办法:       npm 安装依赖分为两种,一是 -g  这种是安装在全局环境的,只有在电脑中 ...

  7. mysql学习笔记--数据库内置函数

    一.数字类 1. 生成随机数:rand() a. 随机抽取2位 select * from stuinfo order by rand() limit 2 2. 四舍五入:round(数字) 3. 向 ...

  8. Python基础测试有关联的接口

    test_guanlian.py放在case文件夹下 test_guanlian.pyimport unittest import requestsfrom urllib.parse import u ...

  9. crm开发之用户ModelForm定制和密码加密

    写了这么多的定制 功能.终于可以定制一下了!因为是 stark 和 rbac 两个组建. 一起使用. 所以在这里,再记录一下.需要注意的点: 先放出 目录结构: 先从  stark 开始.使用star ...

  10. 服务监控-zabbix监控指标

    1.cpu unitzation 监控cpu的整体状态. 使用Zabbix查看CPU利用率,会有下面几个值: CPU idle time:空闲的cpu时间比[简称id] CPU user time:用 ...