<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML xmlns:o = "urn:schemas-microsoft-com:office:office"><HEAD>
<META content="text/html; charset=gb2312" http-equiv=Content-Type>
<STYLE>
BLOCKQUOTE {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px; MARGIN-LEFT: 2em
}
OL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
UL {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
P {
        MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px
}
BODY {
        LINE-HEIGHT: 1.5; FONT-FAMILY: 宋体; COLOR: #000000; FONT-SIZE: 10.5pt
}
</STYLE>
<META name=GENERATOR content="MSHTML 8.00.7601.17940"></HEAD>
<BODY style="MARGIN: 10px">
<DIV>Hi all,</DIV>
<DIV> </DIV>
<DIV>I wrote a sample code to use Rabbitmq management HTTP API. For "Create a
new vhost", it works fine.</DIV>
<DIV> </DIV>
<DIV>
<DIV> HttpPut httpput httpput = new HttpPut();</DIV>
<DIV
style="TEXT-INDENT: 2em">httpput.setHeader("content-type", "application/json");</DIV>
<DIV> httpput.setURI(new URI("<A
href="http://192.168.2.129:55672/api/vhosts/my-vhost">http://192.168.2.129:55672/api/vhosts/my-vhost</A>"));</DIV>
<DIV> DefaultHttpClient httpclient = new DefaultHttpClient(); </DIV>
<DIV> httpclient.getCredentialsProvider().setCredentials(new AuthScope("192.168.2.129", 55672),</DIV>
<DIV> new UsernamePasswordCredentials("guest", "guest"));</DIV>
<DIV> HttpResponse response = httpclient.execute(httpput);</DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>But if I want to create a new Exchange or Queue using the same code, it
always returns NoHTTPResponseException. It seems that once I setEntity for
httpput, the exception occurs.</DIV>
<DIV> </DIV>
<DIV>
<DIV> HttpPut httpput
= new HttpPut();</DIV>
<DIV> httpput.setHeader("content-type", "application/json");</DIV>
<DIV> </DIV>
<DIV> JSONObject param = new JSONObject();</DIV>
<DIV> param.put("type", "direct");</DIV>
<DIV> StringEntity entity = new StringEntity(param.toString());</DIV>
<DIV> httpput.setEntity(entity);</DIV>
<DIV> </DIV>
<DIV> httpput.setURI(new URI("<A
href="http://192.168.2.129:55672/api/exchanges/%2f/my-new-exchange">http://192.168.2.129:55672/api/exchanges/%2f/my-new-exchange</A>"));</DIV>
<DIV> DefaultHttpClient httpclient = new DefaultHttpClient(); </DIV>
<DIV> httpclient.getCredentialsProvider().setCredentials(new AuthScope("192.168.2.129", 55672),</DIV>
<DIV> new UsernamePasswordCredentials("guest", "guest"));</DIV>
<DIV> </DIV>
<DIV> HttpResponse response = httpclient.execute(httpput);</DIV></DIV></DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>Could anyone give me some example how to use HTTP API? Thanks.</DIV>
<DIV> </DIV>
<DIV>Johnson</DIV>
<HR style="WIDTH: 210px; HEIGHT: 1px" align=left color=#b5c4df SIZE=1>
<DIV><SPAN>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US>Best regards,<o:p
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US><FONT style="BACKGROUND-COLOR: #ffff00"
color=#000000></FONT></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US>Johnson 刘峰</SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US>MOBILE:13776621689 <o:p
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US>TEL: 025-83191712</SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US>FAX: 025-58783331<o:p
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">地址:</SPAN><SPAN
style="FONT-SIZE: 12pt"> </SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">南京市雨花区软件大道</SPAN><SPAN
style="FONT-SIZE: 12pt" lang=EN-US>48</SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">号苏豪国际广场</SPAN><SPAN
style="FONT-SIZE: 12pt" lang=EN-US>A</SPAN><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">幢一楼</SPAN><SPAN style="FONT-SIZE: 12pt"
lang=EN-US>A</SPAN><SPAN style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">区</SPAN><SPAN
style="FONT-SIZE: 12pt" lang=EN-US><o:p
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt">邮编:</SPAN><SPAN style="FONT-SIZE: 12pt"
lang=EN-US> 210012</SPAN><SPAN style="FONT-FAMILY: 宋体; FONT-SIZE: 12pt"
lang=EN-US><o:p style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<P style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px" class=MsoNormal><SPAN
style="FONT-SIZE: 12pt" lang=EN-US><IMG id=图片_x0020_1 alt=logo00
src="cid:_Foxmail.0@068F4977-EB05-4117-92BC-875EAC414F50" width=60
height=25></SPAN><SPAN
style="FONT-FAMILY: 'Baskerville Old Face','serif'; FONT-SIZE: 12pt"
lang=EN-US> Information System Co. Ltd.<o:p
style="MARGIN-TOP: 0px; MARGIN-BOTTOM: 0px"></o:p></SPAN></P>
<DIV>
<DIV></DIV></DIV></SPAN></DIV></BODY></HTML>