gpt4 book ai didi

api - Rabbitmq HTTP API 请求未授权

转载 作者:行者123 更新时间:2023-12-01 04:04:13 36 4
gpt4 key购买 nike

我正在尝试使用 http api 请求创建一个新的交换。我用来创建 Exchange 的 URL 是,http://guest:guest@localhost:55672/api/exchanges/%2F/myexq1但它给了我 401 Unauthorized 的错误。我正在使用 chrome rest 客户端来执行此请求。可能是什么原因?任何帮助将不胜感激。

最佳答案

有其他方式解决问题。使用 URL http://guest:guest@localhost:55672/api/exchanges/%2F/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);

我包括的 jar 是:
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

关于api - Rabbitmq HTTP API 请求未授权,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10647631/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com