Rabbitmq HTTP API请求UnAuthorized

我正在尝试使用http api请求创建一个新的交换.我用来创建Exchange的URL是,http:// guest:guest @ localhost:55672 / api / exchanges /// myexq1但是它给了我401 Unauthorized的错误.我正在使用chrome rest客户端来执行此请求.可能是什么原因?任何帮助将不胜感激. 最佳答案 以其他方式解决问题.使用URL http:// guest:guest @ localhost:55672 / api / exchanges /// myexq1时出错.但为了实现我的目标,我写了一个小班.这是代码:

        DefaultHttpClient httpClient = new DefaultHttpClient();         
        HttpHost targetHost = new HttpHost("xx.xx.xx.xx", 55672, "http");

        HttpPut request = new HttpPut(
                "/api/queues/%2F/q1");

        httpClient.getCredentialsProvider().setCredentials(
                new AuthScope(targetHost.getHostName(), targetHost.getPort()), 
                new UsernamePasswordCredentials("guest", "guest"));

        AuthCache authCache = new BasicAuthCache();
        BasicScheme basicAuth = new BasicScheme();
        authCache.put(targetHost, basicAuth);
        BasicHttpContext localcontext = new BasicHttpContext();
        localcontext.setAttribute(ClientContext.AUTH_CACHE, authCache);

        request.addHeader("Content-Type", "application/json");

        StringEntity input = new StringEntity(
                 "{\"vhost\":\"/\",\"durable\":\"false\",\"auto_delete\":\"false\",\"arguments\":{}}");

        request.setEntity(input);

        HttpResponse response = httpClient.execute(targetHost, request, localcontext);

我包括的罐子是:

commons-codec-1.4
commons-logging-1.1.1
httpclient-4.1.3
httpclient-cache-4.1.3
httpcore-4.1.4
httpmime-4.1.3
点赞