我有 curl 命令:
curl -i -u guest:guest -H "content-type:application/json"
-XPUT \ http://localhost:15672/api/traces/%2f/my-trace \
-d'{"format":"text","pattern":"#"}'
我想在 Java API 中创建 HTTP 请求,它会做同样的事情。这个 curl 命令可以在这个README中找到。它用于在 RabbitMQ 上开始记录日志。回应并不重要。
现在我创建了这样的东西(我删除了不太重要的行,即捕获异常等),但不幸的是它不起作用:
url = new URL("http://localhost:15672/api/traces/%2f/my-trace");
uc = url.openConnection();
uc.setRequestProperty("Content-Type", "application/json");
uc.setRequestProperty("format","json");
uc.setRequestProperty("pattern","#")
String userpass = "guest:guest";
String basicAuth = "Basic " + javax.xml.bind.DatatypeConverter.printBase64Binary(userpass.getBytes());
uc.setRequestProperty ("Authorization", basicAuth);