2017-06-29 38 views
0

我知道如何通过WinHTTP 5.1 Automation发送正常文本,以及如何将响应流转换为BigText对象。在Dynamics NAV 2009 SP1中通过WinHTTP 5.1发送BigText

现在我想通过POST/basicly这样就把发送BigText的内容:

CREATE(bigText); 
bigText.ADDTEXT('...'); 
... 
CREATE(HTTP, TRUE, TRUE); 
HTTP.OPEN('PUT', 'https://...', FALSE); 
HTTP.SetCredentials('...', '...', 0); 
HTTP.SEND(bigText); 

的codeunit实际上编译和自动化对象不发送请求到服务器上,但空请求主体。

我试图使用OutStream,但比codeunit不编译(自动化:= OutStream)。

我正在使用Dynamics NAV 2009 SP1,因此也没有DotNet DataType。

+0

你也不能发送对象作为流立即。你需要先序列化它。看到这个答案,我将文件作为XML节点发送。这不完全是你想要的,但你可以适应它。 https://stackoverflow.com/a/44810162/1820340 –

+0

@MakSim已经尝试过使用ADOStream:Microsoft.Dynamics.Nav.Runtime.Nav自动化到Microsoft.Dynamics.Nav.Runtime.NavInStream之间的转换是不可能的,当我想要将ADOStream传递给WinHTTP发送 – Ello

回答

1

我得到了它的流工作兼顾

// Variable Declaration: 
// HTTP = Automation WinHTTP Services 5.1 
// TempBlob = Record <TEMPORARY=YES> TempBlob 
// blobOutStream = OutStream 
// RequestBodyBigText = BigText 
// ResponseBodyBigText = BigText 
// RequestInStream = InStream 
// ReponseInStream = InStream 

// create WinHTTP client, force new instance, don't run locally 
CREATE(HTTP, TRUE, FALSE); 
HTTP.Open('PUT', '...', FALSE); 
HTTP.SetCredentials('...', '....', 0); 
// ... 

// create InStream from BigText by the help of Temporary=YES TempBlob Record 
TempBlob.INIT; 
TempBlob."Blob".CREATEOUTSTREAM(blobOutStream); 
// write the content of the reuquest body to the temp blob 
RequestBodyBigText.WRITE(blobOutStream); 
// important, calcfield the temp blob so that we can use the content 
// in a new stream 
TempBlob.CALCFIELDS("Blob"); 
TempBlob."Blob".CREATEINSTREAM(RequestInStream); 

// send the stream 
HTTP.Send(RequestInStream); 

// timeout is in seconds 
IF HTTP.WaitForResponse(30) THEN BEGIN 
    ResponseInStream := HTTP.ResponseStream; 
    CLEAR(ResponseBodyBigText); 
    ReponseBodyBigText.READ(ResponseInStream); 
END; 

// now we have a big text (ResponseBodyBigText) filled with the body of the response 

如果遇到编码问题,你有皈依功能和EOS循环替换ResponsBodyBigText.READ。如果你不能使用DotNet Interop数据类型(就像我),你可以使用字符集设置为UTF-8的ADOStream自动化,或者使用自己写的COM对象(像我一样)