⑴ 通过http,获取接口的json数据,前面多了三个点
写个servlet,将结果转换成ArrayJson对象,打印出这个json就行,前端通过ajax去请求获得json数据。java转json需要用到相应的jar包,
⑵ 我想向其他的http接口发送JSON数据应该怎么做
先把HTTP获取的数据转换成JSON.通过JSON直接判断.
不然要做的手续太麻烦了,还是要自己解析字符串.增加了难度.
你获取的是JSON标准字符串.
⑶ 怎么开发一个http的接口给返回JSON格式
http,输入文件类型为json
然后里面的内容实用 json 格式就可以了
请采纳!如有疑问,请及时沟通
⑷ 如何向其他的http接口发送JSON数据应该怎么做那通过什么技术可以实现
你说的其实就是webapi呗,对方既然接受JSON数据那肯定是公开接口定义的,你自己组织JSON数据通过ajax发给它就可以了,还需要什么“技术”?前端天天干的不就是这个事儿么……
⑸ java如何使用http方式调用第三方接口最好有代码~谢谢
星号是IP地址和端口号
public class HttpUtil {
private final static Log log = LogFactory.getLog(HttpUtil.class);
public static String doHttpOutput(String outputStr,String method) throws Exception {
Map map = new HashMap();
String URL = "http://****/interface/http.php" ;
String result = "";
InputStream is = null;
int len = 0;
int tmp = 0;
OutputStream output = null;
BufferedOutputStream objOutput = null;
String charSet = "gbk";
System.out.println("URL of fpcy request");
System.out.println("=============================");
System.out.println(URL);
System.out.println("=============================");
HttpURLConnection con = getConnection(URL);
try {
output = con.getOutputStream();
objOutput = new BufferedOutputStream(output);
objOutput.write(outputStr.getBytes(charSet));
objOutput.flush();
output.close();
objOutput.close();
int responseCode = con.getResponseCode();
if (responseCode == 200) {
is = con.getInputStream();
int dataLen = is.available();
int retry = 5;
while (dataLen == 0 && retry > 0) {
try {
Thread.sleep(100);
} catch (InterruptedException e) {
}
dataLen = is.available();
retry--;
log.info("未获取到任何数据,尝试重试,当前剩余次数" + retry);
}
log.info("获取到报文单位数据长度:" + dataLen);
byte[] bytes = new byte[dataLen];
while ((tmp = is.read()) != -1) {
bytes[len++] = (byte) tmp;
if (len == dataLen) {
dataLen = bytes.length + dataLen;
byte[] newbytes = new byte[dataLen];
for (int i = 0; i < bytes.length; i++) {
newbytes[i] = bytes[i];
}
bytes = newbytes;
}
}
result = new String(bytes, 0, len, charSet);
} else {
String responseMsg = "调用接口失败,返回错误信息:" + con.getResponseMessage() + "(" + responseCode + ")";
System.out.println(responseMsg);
throw new Exception(responseMsg);
}
} catch (IOException e2) {
log.error(e2.getMessage(), e2);
throw new Exception("接口连接超时!,请检查网络");
}
con.disconnect();
System.out.println("=============================");
System.out.println("Contents of fpcy response");
System.out.println("=============================");
System.out.println(result);
Thread.sleep(1000);
return result;
}
private static HttpURLConnection getConnection(String URL) throws Exception {
Map map = new HashMap();
int rTimeout = 15000;
int cTimeout = 15000;
String method = "";
method = "POST";
boolean useCache = false;
useCache = false;
HttpURLConnection con = null;
try {
con = (HttpURLConnection) new URL(URL).openConnection();
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new Exception("URL不合法!");
}
try {
con.setRequestMethod(method);
} catch (ProtocolException e) {
log.error(e.getMessage(), e);
throw new Exception("通信协议不合法!");
}
con.setConnectTimeout(cTimeout);
con.setReadTimeout(rTimeout);
con.setUseCaches(useCache);
con.setDoInput(true);
con.setDoOutput(true);
log.info("当前连接信息: URL:" + URL + "," + "Method:" + method
+ ",ReadTimeout:" + rTimeout + ",ConnectTimeOut:" + cTimeout
+ ",UseCaches:" + useCache);
return con;
}
public static void main(String[] args) throws Exception {
String xml="<?xml version=\"1.0\" encoding=\"GBK\" ?><document><txcode>101</txcode><netnumber>100001</netnumber>.........</document>";
response=HttpUtil.doHttpOutput(xml, "post");
JSONObject json= JSONObject.parseObject(response);
String retcode=json.getString("retcode");
调用这个类就能获得返回的参数。。over.
}
}
}
⑹ Java中如何根据一个http接口获取JSON数据,http接口是通过第三方提供,有机构私钥,求代码示例
使用HttpClient,参照代码如下:
http://..com/question/1446921645999461940.html
⑺ 交易所api授权不安全,固定手机lp地此就安全了,是这样吗
这个说法肯定不对,安全不安全,与IP地址固定不固定没有必然的联系,而且如果是用数据,IP地址也是无法固定的,用WIFI,即使固定了路由器的IP地址,外网的IP地址也是无法固定的。
⑻ 如何调用http接口获取json数据及GET/POST方式调用http接口
http接口返回的json数据,其实就是http请求后返回的http主体那一部分。
http协议规定,http头部和http主体之间是以一个空行分割的。因为http每一行(每一行是指一个头部字段)是以\r\n结束的,一个空行的\r\n,再加上最后一行的结束符\r\n,一起是\r\n\r\n,也就是说,当检测到\r\n\r\n四个字符时,下一个字符开始就是http
body的内容了。把http响应主体保存下来就是json数据了。