Welcome, Guest
Username: Password: Remember me
Visual Objects

Please use this forum to post questions about Visual Objects and Vulcan.NET
  • Page:
  • 1

TOPIC:

GetDocumentByGetOrPost 26 Oct 2021 05:25 #20129

  • ny
  • ny's Avatar
  • Topic Author


  • Posts: 6
  • I have an old vo 2.6/2.8 app and after a weeks work it compiles fine in XSharp (via the voxporter). However when I run it I get this runtime error pointing to a problem in GetDocumentByGetOrPost :

    Description : Conversion Error from USUAL (STRING) to PTR
    Subsystem : BASE
    GenCode : EG_DATATYPE Data type error
    FuncSym : USUAL => PTR
    Severity : ES_ERROR
    Can Default : False
    Can Retry : False
    Can Substitute : False
    Argument Type : PTR
    Argument Number : 1
    Argument : USUAL
    Arguments : {{}}
    Expected Argument Type : System.IntPtr
    Stack Trace :
    __USUAL:OP_IMPLICIT (Line: 0)
    MYHTTP2:GETDOCUMENTBYGETORPOST (Line: 94)

    Line 94 (from Norbert's GetDocumentByGetOrPost) is:

    IF HttpSendRequest(SELF:hRequest, ;
    NULL_PTR, ;
    0, ;
    PTR(_CAST, cData), ;
    nDataLen)

    I am sure there are newer ways to do this with .net but my initial aim is to get the same code working in both VO and XSharp.

    Regards, Neale

    Please Log in or Create an account to join the conversation.

    GetDocumentByGetOrPost 26 Oct 2021 13:29 #20137

    • wriedmann
    • wriedmann's Avatar


  • Posts: 3366
  • Hi Neale,
    please do yourself a favor and replace this code with newer code using the .NET classes - it works a lot better.
    I have attached a prg file that I'm using for this.
    Wolfgang
    method GetDocumentByForm( cURL as string, cData as string, nPort as int ) as byte[]
    	local aResult as byte[]
    	local oRequest as System.Net.HttpWebRequest // System.Net.WebRequest
    	local oCredentials as System.Net.NetworkCredential  
    	local oStream as Stream
    	local oResponse as System.Net.HttpWebResponse // System.Net.WebResponse
    	local aData as byte[]
    	local nDataLen as int
    	
    	aResult := byte[]{ 0 }	
    	oRequest := ( System.Net.HttpWebRequest ) System.Net.WebRequest.Create( cURL )
    	if ! String.IsNullOrEmpty( _cUserName )
    		oCredentials := System.Net.NetworkCredential{ _cUserName, _cPassword }
    		oRequest:Credentials := oCredentials
    	endif
    	aData := Encoding.ASCII:GetBytes( cData )
    	nDataLen := aData:Length
    	System.Diagnostics.Debug.WriteLine( "http data:" + cData + "|" + "Length:" + nDataLen:ToString())
    	oRequest:@@Method := "POST"                                           
    	oRequest:Accept := "*/*"
    	oRequest:ContentType := "application/x-www-form-urlencoded"
    	oRequest:ContentLength	:= nDataLen
    	oStream := oRequest:GetRequestStream()
    	oStream:Write( aData, 0, nDataLen )
    	oStream:Close()
    	oResponse := ( System.Net.HttpWebResponse ) oRequest:GetResponse()
    	oStream := oResponse:GetResponseStream()
    	aResult := self:GetBytes( oStream )
    	oStream:Close()
    	return aResult

    File Attachment:

    File Name: httpBase.zip
    File Size:2 KB
    Wolfgang Riedmann
    Meran, South Tyrol, Italy

    www.riedmann.it - docs.xsharp.it
    Attachments:

    Please Log in or Create an account to join the conversation.

    GetDocumentByGetOrPost 26 Oct 2021 14:01 #20138

    • Karl-Heinz
    • Karl-Heinz's Avatar


  • Posts: 774
  • Hi Neale,

    doing something like
    PTR(_CAST, cData)
    is a very bad idea !

    try this:
    LOCAL pData AS PTR
    
    [...]
    
    	pData := MemAlloc ( nDataLen)  // assuming that nDataLen already holds the length of cData !
        
    	MemCopyString ( pData , cData , nDataLen ) 
    
    	HttpSendRequest(SELF:hRequest, ;
    		NULL_PTR, ;
    		0, ;
    		pData, ;
    		nDataLen) 
    
    	Memfree ( pData ) 
    
    [...]

    if it works with X# - i expect it does ;-) -, apply the same changes to the VO side.

    regards
    Karl-Heinz

    Please Log in or Create an account to join the conversation.

    Last edit: by Karl-Heinz.

    GetDocumentByGetOrPost 26 Oct 2021 21:57 #20142

    • ny
    • ny's Avatar
    • Topic Author


  • Posts: 6
  • Thanks for both replies. I am also looking at winHTTPCall - very new to this and still very attached to VO having used it for so long.

    Regards, Neale

    Please Log in or Create an account to join the conversation.

    GetDocumentByGetOrPost 26 Oct 2021 23:21 #20144

    • ic2
    • ic2's Avatar


  • Posts: 1661
  • Hello Neale,

    I am not sure what you want to do with it? Here's another option which returns the content of a URL cPage (I used it for retrieving Teletext =Ceefax in the UK pages):

    Dick
    Method GetFileViaHttp(cPage As String) As String // class TeletekstIC2
    //#s General function to get content of page via http
    Local myRequest As System.Net.HttpWebRequest
    Local myResponse As System.Net.WebResponse
    Local oCachePol As System.Net.Cache.HttpRequestCachePolicy
    Local sr As System.IO.StreamReader
    Local cResult As String
    Try
    	
    myRequest := (System.Net.HttpWebRequest)(System.Net.WebRequest.Create(cPage))
    myRequest:Proxy:=Null   // Otherwise it takes 7 seconds the 1st time this is called
    myRequest:Timeout:=2000 // Only try update server 2 seconds 12-4-2015
    myRequest:@@METHOD:="GET"
    myResponse := myRequest:GetResponse()  // This takes very long if server is not available
    sr := System.IO.StreamReader{myResponse:GetResponseStream(), System.Text.Encoding.GetEncoding("ISO-8859-1")}    // 4-5-2017, ISO instead of UTF8 probably not needed but to be sure
    cResult := sr:ReadToEnd()
    sr:Close()
    myResponse:Close()
    Catch _Exception As System.Exception
    		cResult:=""  // When it's gone wrong, return "" was: assume 404 error
    End Try
    Return  cResult

    Please Log in or Create an account to join the conversation.

    • Page:
    • 1