Bonjour,
j'ai besoin d'utiliser le web service du serveur zabbix et je rencontre un problème d’authentification,j'ai l'exception Unexpected "text/html" content type of the HTTP response
aidez moi s'il vous plait pour trouver une solution.
voici mon code
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import com.thetransactioncompany.jsonrpc2.client.*;
 
//The Base package for representing JSON-RPC 2.0 messages
import com.thetransactioncompany.jsonrpc2.*;
 
//The JSON Smart package for JSON encoding/decoding (optional)
import net.minidev.json.*;
 
//For creating URLs
import java.net.*;
import java.util.HashMap;
import java.util.Map;
 
 
 
public class Example {
 
 
	public static void main(String[] args) {
 
 
		// Creating a new session to a JSON-RPC 2.0 web service at a specified URL
 
		// The JSON-RPC 2.0 server URL
		URL serverURL = null;
 
		try {
			serverURL = new URL("http://server/zabbix/api_jsonrpc.php");
 
		} catch (MalformedURLException e) {
		// handle exception...
		}
 
		// Create new JSON-RPC 2.0 client session
		JSONRPC2Session mySession = new JSONRPC2Session(serverURL);
 
 
		// Once the client session object is created, you can use to send a series
		// of JSON-RPC 2.0 requests and notifications to it.
 
		// Sending an example "authentification" request:
 
		// Construct new request
		String method = "user.authenticate";
		Map<String,String> params = new HashMap<String,String>();
		params.put("user", "user");
		params.put("password", "pwd");
		int requestID =1;
		JSONRPC2Request request = new JSONRPC2Request(method, requestID);
 
		// Send request
		JSONRPC2Response response = null;
 
		try {
			response = mySession.send(request);
 
		} catch (JSONRPC2SessionException e) {
 
		System.err.println(e.getMessage());
		// handle exception...
		}
 
		// Print response result / error
		if (response.indicatesSuccess())
			System.out.println(response.getResult());
		else
			System.out.println(response.getError().getMessage());
 
	}
}