我正在尝试使用http api请求创建一个新的交换。我用来创建交换的网址是,http://guest:guest@localhost:55672/api/exchanges/%2F/myexq1,但它给我的错误是401unsured。我正在使用chrome rest客户端来完成这个请求。可能的原因是什么?任何帮助都将不胜感激。
发布于 2012-05-19 14:35:36
我已经用其他方法解决了这个问题。使用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.3https://stackoverflow.com/questions/10647631
复制相似问题