Home > Back-end >  Problems of the API calls a third party
Problems of the API calls a third party

Time:12-23

Useful to third-party API call hai kang, specific interface is paging to obtain a list of monitory point information
I use a sea kang openAPI development kit in the sample code, attached code (IP, appkey, appSecret I wouldn't have posted)

Public class ArtemisPostTest {
/* *
* please according to your own appKey and appSecret replacement of three parameters in the static static block. Host [1]
* if you choose the docking and field environment, the host IP to be modified for the scene environment, HTTPS port defaults to 443, HTTP port defaults to 80. For example 10.33.25.22:443 or 10.33.25.22:80
* appKey and appSecret follow or get appKey and appSecret changes.
* TODO what is the incoming call to clear before interface, was introduced into json doPostStringArtemis way, download pictures doPostStringImgArtemis method
*/
The static {
ArtemisConfig. Host="XXX";//proxy API gateway nginx server IP port
ArtemisConfig. AppKey="XXXX";//secret key appkey
ArtemisConfig. AppSecret="XXXXX";//secret key appSecret
}
/* *
* ability to open platform site path
Need not modify the path * TODO/Artemis
*/
Private static final String ARTEMIS_PATH="/Artemis";


/* *
* call POST request type (application/json) interface, for intrusion alarm event log here for example
* https://open.hikvision.com/docs/918519baf9904844a2b608e558b21bb6#e6798840
*
* @ return
*/
Public static String callPostStringApi () {
/* *
* http://10.33.47.50/artemis/api/scpms/v1/eventLogs/searches
* according to the API documentation can see that this is a POST request Rest interface, and the incoming parameter values for a json
* ArtemisHttpUtil tools provides doPostStringArtemis this function, a total of six parameters in the document of it, because the interface is HTTPS,
* so the first parameter to the path is a hashmap type, please put a key - value, query for the incoming parameters, the body for the incoming json data
* the incoming contentType for application/json, accept not null is specified for
* the header without additional parameters can not pass, null is specified for
*
*/
Final String getCamsApi=ARTEMIS_PATH + "/API/resource/v1/cameras";
Map Path=new HashMap (2) {
{
Put (" https://", getCamsApi);//according to the deployment environment to confirm is the HTTP or HTTPS
}
};

JSONObject jsonBody=new JSONObject ();

JsonBody. Put (" pageNo ", 1);
JsonBody. Put (" pageSize ", 3);
String body=jsonBody. ToJSONString ();

String result=ArtemisHttpUtil. DoPostStringArtemis (path, body, null, null, "application/json", null);//post request application/json type parameter
return result;
}


I built the main self-test method calls when I print the error message is


Don't know what a big call over the sea, API, please help answer

CodePudding user response:

You is this 404 people return code will give you the clearly so it must be you in the right path

CodePudding user response:

For your getCamsApi carefully, does he write wrong

CodePudding user response:

Check your IP address and transfer the interface

CodePudding user response:

DoPostStringArtemis method is how to implement, have the code? Will not be sent directly using the map the path parameter value and forget stitching domain or IP?

CodePudding user response:

Hello, I'm the problem, are you solved

CodePudding user response:

Should be ArtemisConfig. Host to fill a fault, or, previewURLsApi fill wrong,

PreviewURLsApi to fill the possibility of more, fault,

The final String getCamsApi=ARTEMIS_PATH + "/API/resource/v1/cameras";
Replace final String getCamsApi=ARTEMIS_PATH + "/API/SCPMS/v1/eventLogs/searches".
Or final String getCamsApi=ARTEMIS_PATH + "/API/SCPMS/v2/eventLogs/searches".

Should be ok,

CodePudding user response:

The solution? How to get rid of, I also encountered this problem

CodePudding user response:

To learn how to troubleshoot problems, what conditions will lead to 404,
  • Related