我试着连接业务中心与共享点,我已经这样做了在 Postman ,它的工作很好,获得和张贴。但现在我试图这样做的BC,令牌已创建,但不工作,我认为它有一些问题的连接或网址的。
codeunit 50100 "APISharePoint"
{
var
OAuth2: Codeunit OAuth2;
ClientIdTxt: Label '4d148348-137a-40e7-b20c-a458c2a03c65', Locked = true;
ClientSecret: Label 'Ai2pOhE7yeZ8WRxrwSrHdpVtNqJg51tg2X+s8CJDLy4=', Locked = true;
ResourceUrlTxt: Label 'https://crmbc384959.sharepoint.com', Locked = true;
OAuthAuthorityUrlTxt: Label 'https://login.microsoftonline.com/ec36749a-af47-4f04-892c-98666b6cac1b/oauth2/v2.0/token', Locked = true;
procedure GetAccessToken(): Text
var
PromptInteraction: Enum "Prompt Interaction";
AccessToken: Text;
AuthCodeError: Text;
RedirectURLTxt: Text;
begin
// OAuth2.GetDefaultRedirectURL(RedirectURLTxt);
RedirectURLTxt := 'https://localhost';
if OAuth2.AcquireTokenWithClientCredentials(ClientIdTxt, ClientSecret, OAuthAuthorityUrlTxt, RedirectURLTxt, ResourceURLTxt, AccessToken) then
exit(AccessToken)
else
exit('');
end;
procedure HttpGet(AccessToken: Text; Url: Text /*var JResponse: JsonObject*/): Boolean
var
Client: HttpClient;
Headers: HttpHeaders;
RequestMessage: HttpRequestMessage;
ResponseMessage: HttpResponseMessage;
RequestContent: HttpContent;
ResponseText: Text;
IsSucces: Boolean;
begin
Headers := Client.DefaultRequestHeaders();
Headers.Add('Authorization', StrSubstNo('Bearer %1', AccessToken));
Headers.Add('Accept', 'application/json;odata=verbose');
RequestMessage.Content.GetHeaders(Headers); //asd
Headers.Remove('Content-Type');
Headers.Add('Content-Type', 'application/json;odata=verbose');
RequestMessage.SetRequestUri(Url);
RequestMessage.Method := 'GET';
if Client.Send(RequestMessage, ResponseMessage) then
if ResponseMessage.IsSuccessStatusCode() then begin
if ResponseMessage.Content.ReadAs(ResponseText) then
IsSucces := true;
// end else
// ResponseMessage.Content.ReadAs(ResponseText);
// JResponse.ReadFrom(ResponseText);
exit(IsSucces);
end;
end;
1条答案
按热度按时间whitzsjs1#
也许你的问题是GET和请求内容的组合。据我所知,HttpClient在.NET中的底层实现不支持GET和请求内容。你可以在这里阅读更多关于它的信息:How to use HttpClient to send content in body of GET request?
也许您可以尝试GET而不对内容设置content-type,或者使用POST或PUT。
但您没有提供错误消息,因此这只是猜测。