PB 调用HTTP接口
/*1).请求地址:
"http://192.168.31.100:8069/zimo_rfids/pirfids_tags.api"
2).调用方式: HTTP post
3).接口描述:
接口描述详情
头部信息: Content-Type :application/json
4).请求参数:(示例参考)
{
"params": {
"tag_value": "mark_reset_count",
"reader_value": "ZMPIDCA6323F8EDD",
"value": " ",
"time": "2020-03-20 02:11:11"
} }
*/
n_httpresponse httpResponse
n_json json,jsonParm,jsonResult
n_httpClient httpClient
String ls_tt1,ls_tt2
String ls_where
json = Create n_json
jsonParm = Create n_json
httpClient = Create n_httpClient
//构建JSON数据包
//该数据包字符串化为:
//'{"params":{"tag_value": "mark_reset_count","reader_value": "ZMPIDCA6323F8EDD","value": " ","time": "2020-03-20 02:11:11"}}'
jsonParm.SetItem('tag_value','mark_reset_count')
jsonParm.SetItem('reader_value','ZMPIDCA6323F8EDD')
jsonParm.SetItem('value','')
jsonParm.SetItem('time','2020-03-20 02:11:11')
json.SetItem("params",jsonParm)
//发送请求并接收响应数据
//*发送JSON对象时默认Content-Type为application/json; charset=utf-8,你也可以手动指定为其它的
httpResponse = httpClient.Request(Enums.HTTP_METHOD_POST,"http://192.168.31.100:8069/zimo_rfids/pirfids_tags.api",json ) //
//显示响应结果
if httpResponse.IsValid() then
ls_tt1 = "Headers:~r~n" + httpResponse.GetHeaders() + "~r~nResponse:~r~n" + httpResponse.GetDataString()
else
ls_tt2 = "Error:" + String(httpResponse.GetError()) + "~r~nError Info:~r~n" + httpResponse.GetErrorInfo()
end if
//获取JSON数据(自动解析为JSON对象)
jsonResult = httpResponse.GetDataJSON()
//取响应数据的sign节点值
MessageBox("result",jsonResult.GetItemString("result"))
MessageBox("result2",jsonResult.GetItemString("jsonrpc"))
Destroy json
Destroy jsonParm