フィルターのクリア

Using matlab.net​.http.Requ​estMessage​.Send with NTLM authentication

5 ビュー (過去 30 日間)
Thien Pham
Thien Pham 2017 年 8 月 3 日
コメント済み: Andrew Stamps 2017 年 10 月 23 日
Good day,
I have a need to call a web API from my matlab code which has been secured with NTLM authentication on the server side.
I tried the following matlab functionality but cannot seem to get around the authentication problem: 1) webwrite 2) matlab.net.http.RequestMessage.send(scope, options) where options = HTTPOptions('Credentials',Credentials('Username','xyz','Password','abc','Scope',URI(strUrl)),'ConnectTimeout',30)
Can you advise if/how I can make the web call work under NTLM authentication.
Thank you. Thien

回答 (2 件)

Thien Pham
Thien Pham 2017 年 10 月 23 日
Hi Andy,
Below extract from the code, as I can verify it does work for NTLM authentication (in fact according to MS the class should handle any authentication challenges automatically).
You need to replace the variables ending in _XXX suffix with your objects. The returned strContent is a valid JSON string which you then need to parse. There's an example of a working parser class in Matlab.
NET.addAssembly('System'); NET.addAssembly('System.Net'); NET.addAssembly('System.Net.Http'); NET.addAssembly('System.Threading.Tasks'); import System.*; import System.Net.*; import System.Net.Http.*; import System.Net.Http.Headers.*;
clientHandler = HttpClientHandler; clientHandler.Credentials = CredentialCache.DefaultNetworkCredentials; client = HttpClient(clientHandler); client.BaseAddress = Uri(strUrl_XXX); client.Timeout = TimeSpan.FromSeconds(90); client.DefaultRequestHeaders.Accept.Clear(); mediatype = MediaTypeWithQualityHeaderValue('application/json'); client.DefaultRequestHeaders.Accept.Add(mediatype);
jsonParams = this.api_create_json(ParamsStructure_XXX); objParams = StringContent(jsonParams, System.Text.Encoding.UTF8, 'application/json'); response = client.PostAsync(strUrl, objParams).Result;
objContent = response.Content.ReadAsStringAsync(); strContent = char(objContent.Result);
  1 件のコメント
Andrew Stamps
Andrew Stamps 2017 年 10 月 23 日
Thank you. This is generally what I needed.

サインインしてコメントする。


Morrie Gasser
Morrie Gasser 2017 年 8 月 7 日
Unfortunately, as of R2017a, the HTTP interface (classes in matlab.net.http) and webwrite do not support NTLM. It is supported by webread, but only for the GET method.
  2 件のコメント
Thien Pham
Thien Pham 2017 年 8 月 7 日
Thanks for confirming this Morrie.
I have found a somewhat convoluted workaround by using .NET HttpClient which seems to resolve the authentication issue.
Thien
Andrew Stamps
Andrew Stamps 2017 年 10 月 20 日
Thien,
Any chance you could share this workaround? I am experiencing a similar issue.
Thanks, Andy

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by