473,387 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

InternetReadFile error


Hello,

I've looked through several newsgroups and have yet to find help with this
problem. We have a device we can access through IE, using a URL, that
returns an XML string.

For example, typing
"http://192.168.1.254/cgi-bin/dataProxy?oper=queryEvents&raw=1" into IE
returns this XML String:
<?xml version="1.0" ?>
- <Matrics>
- <EventGroup>
- <EventList>
<Tag event="1" raw="03080507A80200100009415D" time="41dd2180" RPL="1" />
<Tag raw="03080507A802001000257310" time="41dd170b" />
</EventList>
</EventGroup>
</Matrics>

In VB6 I got this to work, as a test, using a form and the following
subroutine:

Private Sub QueryReader(strIPAddress As String, intPort As Integer,
strFormat As String)
On Error GoTo Err_QueryReader

Dim hInternet As Long
Dim hConnect As Long
Dim hRequest As Long
Dim bRes As Boolean
Dim lBytesRead As Long
Dim strURL As String, strData As String
Dim x As Long

hInternet = InternetOpen("Test", INTERNET_OPEN_TYPE_PRECONFIG,
vbNullString, vbNullString, 0)
hConnect = InternetConnect(hInternet, strIPAddress, intPort, "", "",
INTERNET_SERVICE_HTTP, 0, 0)

strURL = "/cgi-bin/dataProxy?oper=queryEvents"
If strFormat = "Raw" Then strURL = strURL & "&raw=1"
hRequest = HttpOpenRequest(hConnect, "GET", strURL, vbNullString,
vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
bRes = HttpSendRequest(hRequest, vbNullString, 0, 0, 0)

' If request was valid, get the data
If CBool(bRes) Then
Dim sBuffer As String * 65000
sBuffer = ""
bRes = InternetReadFile(hRequest, sBuffer, Len(sBuffer), lBytesRead)
If lBytesRead > 0 Then

' Store inventory History record and the associated part record
Dim cmd As New ADODB.Command
Dim prm As New ADODB.Parameter
Set cmd = Nothing
Set cmd.ActiveConnection = cnn
With cmd
.CommandText = "UpdateRFIDInformation"
.CommandType = adCmdStoredProc

strData = Trim(sBuffer)
strData = Replace(strData, "<?xml version='1.0'?>", "")
strData = Replace(strData, "'", Chr(34))

Set prm = .CreateParameter("data", adVarChar, adParamInput,
65000, strData)
.Parameters.Append prm

Set prm = .CreateParameter("ip", adVarChar, adParamInput,
15, strIPAddress)
.Parameters.Append prm
.Execute
End With
End If
End If
bRes = InternetCloseHandle(hInternet)

Exit_QueryReader:
Set cmd = Nothing
Set prm = Nothing
Exit Sub

Err_QueryReader:
MsgBox Err.Description
GoTo Exit_QueryReader

End Sub
SO then I wanted to use VB.NET to create this as a system service but the
call to InternetReadFile never returns anything in the buffer. I'm assuming
it might have something to do with my function declaration. I've tried
numerous things and still come up with nothing. Any help would be
appreciated. The .NET code is below:

Public Declare Auto Function InternetReadFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As System.Text.StringBuilder, _
ByVal lNumberOfBytesToRead As Long, ByRef lNumberOfBytesRead As
Long) As Long
Sub QueryReader(ByVal strIPAddress As String, ByVal intPort As Int32,
ByVal strFormat As String)

Dim hInternet As Long
Dim hConnect As Long
Dim hRequest As Long
Dim bRes As Long
Dim lBytesRead As Long
Dim strURL As String, strData As String
Dim Buffer As New System.Text.StringBuilder(BufLen)
Dim nSize As Integer = Buffer.Capacity
Try

hInternet = InternetOpen("RFID Monitor",
INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)
hConnect = InternetConnect(hInternet, strIPAddress, intPort, "",
"", INTERNET_SERVICE_HTTP, 0, 0)

strURL = "/cgi-bin/dataProxy?oper=queryEvents"
If strFormat = "Raw" Then strURL = strURL & "&raw=1"

hRequest = HttpOpenRequest(hConnect, "GET", strURL,
vbNullString, vbNullString, 0, INTERNET_FLAG_RELOAD, 0)
bRes = HttpSendRequest(hRequest, vbNullString, 0, 0, 0)

' If request was valid, get the data
If bRes Then

bRes = InternetReadFile(hRequest, Buffer, nSize, lBytesRead)
Console.WriteLine(bRes)

Dim myEx As New Win32Exception(bRes)
Console.WriteLine(myEx.Message)
Console.WriteLine(myEx.ErrorCode)
Console.WriteLine(myEx.HelpLink)
Console.WriteLine(myEx.Source)

If lBytesRead > 0 Then
Dim cmd As New
SqlClient.SqlCommand("UpdateRFIDInformation", AT)
cmd.CommandType = CommandType.StoredProcedure
With cmd
strData.Trim()
strData.Replace("<?xml version='1.0'?>", "")
strData.Replace("'", Chr(34))

.Parameters.Add("@xml", strData)
.Parameters.Add("@IPAddress", strIPAddress)
.ExecuteNonQuery()
End With
End If

End If

Catch ex As Exception
EventLog1.WriteEntry(ex.Message)
Finally
bRes = InternetCloseHandle(hInternet)

End Try
--
Cheri Reed
Nov 21 '05 #1
3 3656
"Cheri Reed" <Ch*******@discussions.microsoft.com> schrieb:
I've looked through several newsgroups and have yet to find help with this
problem. We have a device we can access through IE, using a URL, that
returns an XML string.


Your declares are incorrect, 'Long' has to be replaced by 'Int32', and some
other changes need to be applied. Is there any reason why you are not using
the .NET class 'HttpWebRequest' instead of the p/invoke solution?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #2

I'll try replacing Long with Int32. I need to specify the port being used
and I thought HttpWebRequest didn't have this capability.
"Herfried K. Wagner [MVP]" wrote:
"Cheri Reed" <Ch*******@discussions.microsoft.com> schrieb:
I've looked through several newsgroups and have yet to find help with this
problem. We have a device we can access through IE, using a URL, that
returns an XML string.


Your declares are incorrect, 'Long' has to be replaced by 'Int32', and some
other changes need to be applied. Is there any reason why you are not using
the .NET class 'HttpWebRequest' instead of the p/invoke solution?

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #3
"Cheri Reed" <Ch*******@discussions.microsoft.com> schrieb:
I need to specify the port being used
and I thought HttpWebRequest didn't have this capability.


You can try to specify the port in the URL (untested!):

<URL:http://www.google.de/groups?threadm=hxoGxFErEHA.1344%40cpmsftngxa06.phx .gbl>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: AIM | last post by:
Error in msvc in building inheritance.obj to build hello.pyd Hello, I am trying to build the boost 1.31.0 sample extension hello.cpp. I can not compile the file inheritance.cpp because the two...
5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
1
by: ree | last post by:
When I download the files using InternetReadFile, they seem to lose the formating all the spaces gets removed, and thus I can't open the file. Here is the file (it a doc fie) ________ ÐÏࡱá
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
2
by: Cheri Reed | last post by:
Hello, I've looked through several newsgroups and have yet to find help with this problem. We have a device we can access through IE, using a URL, that returns an XML string. For example,...
1
by: marfi95 | last post by:
Is there a way to make the internetreadfile function read records that are terminated by newlines instead of reading into a buffer. It would make it much easier for me to process. I suppose I...
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.