2016-03-30 16 views
0

Azure API管理Rest Serviceを初めて使用しました。私はsharedaccesstokenで新しいAPI管理を作成しました。Azure API管理Restサービスを使用してユーザーを作成する

using (HttpClient httpClient = new HttpClient()) 
{ 
    var request = new HttpRequestMessage(HttpMethod.Post, requestUrl); 
    request.Headers.Authorization = 
    new AuthenticationHeaderValue("SharedAccessSignature", sharedAccessSignature); 
    request.Content = new StringContent("{\"accountEnabled\": true,\"creationType\": \"LocalAccount\",\"displayName\": \"Alex Wu\",\"passwordProfile\": {\"password\": \"Test1234\",\"forceChangePasswordNextLogin\": false},\"signInNames\": [{\"type\": \"userName\",\"value\": \"AlexW\"},{\"type\": \"emailAddress\",\"value\": \"[email protected]\"}]}"); 
    HttpResponseMessage response = await httpClient.SendAsync(request); 
    response.EnsureSuccessStatusCode(); 
    responseBody = await response.Content.ReadAsStringAsync(); 
} 

私は上記のコードを実行し、エラーを取得:

{StatusCode: 405, ReasonPhrase: 'Method Not Allowed', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:{ Date: Wed, 30 Mar 2016 19:38:15 GMT Content-Length: 73 Allow: GET Content-Type: application/json; charset=utf-8}} 

誰かが私はので、私はRESTサービスを介して、新規ユーザーを作成することができます前進を助けることができます。

答えて

0

私はちょうどhttps://msdn.microsoft.com/en-us/library/dn776330.aspx#CreateUserで指定されたAPIリファレンスを読みました。

はじめに、投稿の代わりにHttpMethod.Putを使用する必要があります。要求パスは、ベースURL +/users/{unique uid}でなければなりません。また、私が知ることから、あなたが渡そうとしている属性はこのトランザクションで利用できません。

実際にAzure API管理ユーザーエンティティを作成しようとしている場合は、アドバイスをお願いします。さらにご案内します。

0

あなたの答えは本当に助けになりました。私の仕事を成し遂げた実装の下に。

string requestUrl = string.Format("{0}/users/{1}?api-version={2}", baseUrl, userGuid, apiVersion); 
      string responseBody = null; 
      try 
      { 
       using (HttpClient httpClient = new HttpClient()) 
       { 
var request = new HttpRequestMessage(HttpMethod.Put, requestUrl); 
         request.Headers.Authorization = 
          new AuthenticationHeaderValue("SharedAccessSignature", sharedAccessSignature); 
         request.Content = new StringContent("{\"firstName\": \"MyFirstName\",\"lastName\": \"MyLastName\",\"email\": \"[email protected]\",\"password\": \"Password;\",\"state\": \"active\"}", Encoding.UTF8,"application/json"); 
         HttpResponseMessage response = await httpClient.SendAsync(request);`enter code here` 
         response.EnsureSuccessStatusCode(); 
         responseBody = await response.Content.ReadAsStringAsync(); 
} 
      } 
関連する問題