~~~
/*
* 如有疑問可與技術聯系QQ:706448591
*/
package api51;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.URL;
import java.net.URLConnection;
public class shenfenzheng {
public static void main(String[] args) {
String appcode = "你自己的AppCode";
String url = "http://shenfenzhe.market.alicloudapi.com/do";
String imageurl = "http://storage.api51.cn/demo/zheng.jpg";
String params= "image="+imageurl+"&id_card_side=front";
//發送 POST 請求
String sr=shenfenzheng.sendPost(url, params,appcode);
System.out.println(sr);
}
/**
* 向指定 URL 發送POST方法的請求
*
* @param url
* 發送請求的 URL
* @param param
* 請求參數,請求參數應該是 name1=value1&name2=value2 的形式。
* @return 所代表遠程資源的響應結果
*/
public static String sendPost(String url, String param, String appcode) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打開和URL之間的連接
URLConnection conn = realUrl.openConnection();
// 設置通用的請求屬性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Authorization", "APPCODE "+appcode);
// 發送POST請求必須設置如下兩行
conn.setDoOutput(true);
conn.setDoInput(true);
// 獲取URLConnection對象對應的輸出流
out = new PrintWriter(conn.getOutputStream());
// 發送請求參數
out.print(param);
// flush輸出流的緩沖
out.flush();
// 定義BufferedReader輸入流來讀取URL的響應
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("發送 POST 請求出現異常!"+e);
e.printStackTrace();
}
//使用finally塊來關閉輸出流、輸入流
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
return result;
}
/**
* 向指定URL發送GET方法的請求
*
* @param url
* 發送請求的URL
* @param param
* 請求參數,請求參數應該是 name1=value1&name2=value2 的形式。
* @return URL 所代表遠程資源的響應結果
*/
public static void main(String[] args) {
String appcode = "購買后在控制臺查看Appcode";
String url = "請求地址";
String params= "請求參數";//示例:code=123
//發送 GET 請求
String s=api51.sendGet(url, params,appcode);
System.out.println(s);
/*
//發送 POST 請求
String sr=api51.sendPostt(url, params,appcode);
System.out.println(sr);
*/
}
public static String sendGet(String url, String param, String appcode) {
String result = "";
BufferedReader in = null;
try {
String urlNameString = url + "?" + param;
URL realUrl = new URL(urlNameString);
// 打開和URL之間的連接
URLConnection connection = realUrl.openConnection();
// 設置通用的請求屬性
connection.setRequestProperty("accept", "*/*");
connection.setRequestProperty("connection", "Keep-Alive");
connection.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
connection.setRequestProperty("Authorization", "APPCODE "+appcode);
// 建立實際的連接
connection.connect();
// 獲取所有響應頭字段
Map<String, List<String>> map = connection.getHeaderFields();
// 遍歷所有的響應頭字段
for (String key : map.keySet()) {
// System.out.println(key + "--->" + map.get(key));
}
// 定義 BufferedReader輸入流來讀取URL的響應
in = new BufferedReader(new InputStreamReader(
connection.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("發送GET請求出現異常!" + e);
e.printStackTrace();
}
// 使用finally塊來關閉輸入流
finally {
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
/**
* 向指定 URL 發送POST方法的請求
*
* @param url
* 發送請求的 URL
* @param param
* 請求參數,請求參數應該是 name1=value1&name2=value2 的形式。
* @return 所代表遠程資源的響應結果
*/
public static String sendPost(String url, String param, String appcode) {
PrintWriter out = null;
BufferedReader in = null;
String result = "";
try {
URL realUrl = new URL(url);
// 打開和URL之間的連接
URLConnection conn = realUrl.openConnection();
// 設置通用的請求屬性
conn.setRequestProperty("accept", "*/*");
conn.setRequestProperty("connection", "Keep-Alive");
conn.setRequestProperty("user-agent",
"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
conn.setRequestProperty("Authorization", "APPCODE "+appcode);
// 發送POST請求必須設置如下兩行
conn.setDoOutput(true);
conn.setDoInput(true);
// 獲取URLConnection對象對應的輸出流
out = new PrintWriter(conn.getOutputStream());
// 發送請求參數
out.print(param);
// flush輸出流的緩沖
out.flush();
// 定義BufferedReader輸入流來讀取URL的響應
in = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
String line;
while ((line = in.readLine()) != null) {
result += line;
}
} catch (Exception e) {
System.out.println("發送 POST 請求出現異常!"+e);
e.printStackTrace();
}
//使用finally塊來關閉輸出流、輸入流
finally{
try{
if(out!=null){
out.close();
}
if(in!=null){
in.close();
}
}
catch(IOException ex){
ex.printStackTrace();
}
}
return result;
}
}
~~~
- API無憂介紹
- 短信驗證碼接口
- 簽名模板審核標準
- 短信簽名審核規則
- 短信模板審核規則
- 普通短信
- 營銷短信
- 申請簽名的常見問題
- 接口說明
- 單發接口
- 群發接口
- 無參數單發接口
- 代碼示例
- 【測試推薦】純前端ajax代碼
- Python代碼示例
- php代碼示例
- java代碼示例
- curl代碼示例
- ObjectC代碼示例
- C#代碼示例
- 錯誤碼
- 常用模板
- 返回說明
- 頻率限制
- 國際短信價格表
- 在阿里云市場購買的短信接口說明
- 短信調用demo(ajax版)
- 前端代碼
- ajaxsms.php
- php post示例代碼
- 短信計費說明
- 阿里云市場說明
- 阿里云調用次數的說明
- 阿里云市場GET/POST方法
- php版本
- java版本
- python3版本
- ajax版本
- 阿里云店鋪
- 身份證識別接口
- 身份證識別購買說明
- 身份證識別接口請求說明
- 簡道云集成身份證識別接口
- 基金數據接口
- 當前數據查詢
- 歷史數據查詢
- 基金接口存檔
- 金融數據接口
- 產品說明
- 產品代碼表
- 股票代碼
- 股指代碼
- 股指期貨代碼
- 數字貨幣代碼
- 外匯代碼
- 國內期貨代碼
- 國際期貨代碼
- v1產品留檔
- ETF代碼表
- 大宗商品代碼表
- 股指期貨代碼表
- 債券代碼表
- 股指代碼表
- 數字貨幣數據
- 外匯代碼表
- 貴金屬代碼表
- 金融數據圖表代碼下載
- 金融數據返回結果說明
- 金融數據調用代碼(java)
- 金融數據調用代碼(php)
- V2產品留檔
- V3外匯高頻
- 在線調試
- 金融數據報價查詢
- 下線接口留檔
- 新獨立數據平臺
- 報價real
- 分筆tick
- 分時trend
- K線kline
- 資料info
- 個股資料
- 股東資料
- 財務信息
- 所屬板塊
- 資金流fundflow
- 排序sort
- 各市場排序
- 指數排序
- 資金流排序
- 板塊列表排序
- 板塊內個股排序
- 檢索search
- 新聞news
- 新聞列表
- 新聞詳情
- 高速多產品查詢
- 港美股數據接口
- 報價查詢
- 分時圖查詢
- 舊股票數據接口(已下線)
- 股票接口說明
- 實時數據
- K線數據
- 分時數據
- 5日分時
- F10數據查詢
- 公司概況
- 行情_排序
- 滬深股票列表
- 香港股票列表
- 美國股票列表
- 板塊查詢說明
- 期貨列表查詢
- 行情_分筆
- 板塊_關系
- 查詢_除息除權
- 新股日歷
- 滬深資訊簡報
- 股票代碼說明
- 股票常見問題
- 交易狀態
- 股票demo說明
- 支持外匯品種
- 支持期貨品種
- 財經日歷
- 快遞查詢接口
- 快遞公司代碼表
- 快遞查詢代碼(php)
- 快遞查詢返回結果
- 圖形驗證碼識別接口
- 滑塊驗證碼