GetDocumentByGetOrPost

Public support forum for peer to peer support with related to the Visual Objects and Vulcan.NET products
Post Reply
ny
Posts: 6
Joined: Tue Oct 06, 2020 10:23 am

GetDocumentByGetOrPost

Post by ny »

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
User avatar
wriedmann
Posts: 3754
Joined: Mon Nov 02, 2015 5:07 pm
Location: Italy

GetDocumentByGetOrPost

Post by wriedmann »

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

Code: Select all

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
httpBase.zip
(1.53 KiB) Downloaded 76 times
Wolfgang Riedmann
Meran, South Tyrol, Italy
wolfgang@riedmann.it
https://www.riedmann.it - https://docs.xsharp.it
Karl-Heinz
Posts: 774
Joined: Wed May 17, 2017 8:50 am
Location: Germany

GetDocumentByGetOrPost

Post by Karl-Heinz »

Hi Neale,

doing something like

Code: Select all

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

try this:

Code: Select all

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
ny
Posts: 6
Joined: Tue Oct 06, 2020 10:23 am

GetDocumentByGetOrPost

Post by ny »

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
ic2
Posts: 1858
Joined: Sun Feb 28, 2016 11:30 pm
Location: Holland

GetDocumentByGetOrPost

Post by ic2 »

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

Code: Select all

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
Post Reply