C#调用安全验证下的ActiveMQ REST管理接口
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- using System.Net;
- using System.IO;
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String url = textBox2.Text;
- String admin = url.Substring(0, url.IndexOf("hawtio")) + "admin/";
- HttpWebRequest request = WebRequest.Create(admin) as HttpWebRequest;
- request.CookieContainer = new CookieContainer();
- request.KeepAlive = false;
- request.AllowAutoRedirect = false;
- request.PreAuthenticate = true;
- request.Credentials = new System.Net.NetworkCredential("admin", "admin");
- WebResponse response = null;
- try
- {
- response = request.GetResponse();
- }
- catch (Exception ex)
- {
- textBox1.Text = ex.Message;
- }
- if (response != null)
- {
- Stream s = response.GetResponseStream();
- StreamReader sr = new StreamReader(s, Encoding.Default, true);
- string html = sr.ReadToEnd();
- Encoding encoding = sr.CurrentEncoding;
- sr.Close();
- s.Close();
- response.Close();
- HttpWebRequest request1 = WebRequest.Create(url) as HttpWebRequest;
- request1.KeepAlive = false;
- request1.AllowAutoRedirect = false;
- request1.PreAuthenticate = true;
- request1.Credentials = request.Credentials;
- request1.CookieContainer = request.CookieContainer;
- request1.Headers.Set("Authorization", request.Headers.Get("Authorization"));
- response = request1.GetResponse();
- if (response != null)
- {
- s = response.GetResponseStream();
- sr = new StreamReader(s, Encoding.Default, true);
- string json = sr.ReadToEnd();
- sr.Close();
- s.Close();
- response.Close();
- textBox1.Text = json;
- }
- }
- }
- }
- }
2. [图片] 1.jpg
3. [代码][C#]代码
4. [图片] 1.jpg
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · salesforce rest api test class
- · ActiveMQ资料大全
- · ActiveMQ REST Management API
- · The instance of entity type ‘Customer’ cannot be tracked because another instance with the same key value for {‘Id’} is already being tracked.
- · .NET8实时更新nginx ip地址归属地
- · 解决.NET Blazor子组件不刷新问题
- · .NET8如何在普通类库中引用 Microsoft.AspNetCore
- · .NET8 Mysql SSL error
- · ASP.NET Core MVC的Razor视图渲染中文乱码的问题
- · 消息队列RabbitMQ版 网络异常自动恢复
- · .NETCORE 依赖注入服务生命周期
- · RabbitMQ的工作原理及安装