accessing data from service bus

天大地大妈咪最大 提交于 2020-01-16 08:05:54

问题


I am trying to connect to servicebus and getting data from it, it seems since I've got the token I must reuse it evertime I make a request what's wrong with this code?here is the error I've got at the last line The remote server returned an error: (401) Unauthorized.

//sample usage string mydata1 = string.Format(Constants.myData, brfId);

public static readonly myData= "https://sdgsdg.servicebus.windows.net/sgsdg/gdgsg/{0}";



//sample usage - string agendaByBriefingDetailIdURI = string.Format(Constants.myData2 BriefingID, accessCode);

public static readonly string myData2= "https://sdgsg.servicebus.windows.net/sdg/dgsg/{0}/{1}";

    string SCOPE = "http://lalalalala.servicebus.windows.net/";

    string WRAP_PASSWORD = "lalalalalala"

    string WRAP_USERNAME = "lalalala";

    string ACS_NAMESPACE = "lalalalala";

    WebClient client = new WebClient();

    client.BaseAddress = string.Format("https://{0}.accesscontrol.windows.net", ACS_NAMESPACE);




    NameValueCollection values = new NameValueCollection();

    values.Add("wrap_name", WRAP_USERNAME);

    values.Add("wrap_password", WRAP_PASSWORD);

    values.Add("wrap_scope", SCOPE);


    // WebClient takes care of the URL Encoding

    byte[] responseBytes = client.UploadValues("WRAPv0.9", "POST", values);


    // the raw response from ACS

    string response = Encoding.UTF8.GetString(responseBytes);

    string token = response.Split('&').Single(x => x.StartsWith("wrap_access_token=", StringComparison.OrdinalIgnoreCase)).Split('=')[1];

    string decodedToken = HttpUtility.UrlDecode(token);

    string.Format("WRAP access_token=\"{0}\"", HttpUtility.UrlDecode(token));


    WebClient webClient = new WebClient();

    webClient.Headers["Authorization"] = string.Format("WRAP access_token=\"{0}\"", HttpUtility.UrlDecode(token));


    string returnString = webClient.DownloadString(string.Format(mystaticre, 10));

来源:https://stackoverflow.com/questions/35292136/accessing-data-from-service-bus

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!