473,849 Members | 1,802 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

InternetReadFil e 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="03080507A8 0200100009415D" time="41dd2180" RPL="1" />
<Tag raw="03080507A8 02001000257310" 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(str IPAddress 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("T est", INTERNET_OPEN_T YPE_PRECONFIG,
vbNullString, vbNullString, 0)
hConnect = InternetConnect (hInternet, strIPAddress, intPort, "", "",
INTERNET_SERVIC E_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_R ELOAD, 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 = InternetReadFil e(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.ActiveConne ction = cnn
With cmd
.CommandText = "UpdateRFIDInfo rmation"
.CommandType = adCmdStoredProc

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

Set prm = .CreateParamete r("data", adVarChar, adParamInput,
65000, strData)
.Parameters.App end prm

Set prm = .CreateParamete r("ip", adVarChar, adParamInput,
15, strIPAddress)
.Parameters.App end prm
.Execute
End With
End If
End If
bRes = InternetCloseHa ndle(hInternet)

Exit_QueryReade r:
Set cmd = Nothing
Set prm = Nothing
Exit Sub

Err_QueryReader :
MsgBox Err.Description
GoTo Exit_QueryReade r

End Sub
SO then I wanted to use VB.NET to create this as a system service but the
call to InternetReadFil e 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 InternetReadFil e Lib "wininet.dl l" _
(ByVal hFile As Long, ByVal sBuffer As System.Text.Str ingBuilder, _
ByVal lNumberOfBytesT oRead As Long, ByRef lNumberOfBytesR ead As
Long) As Long
Sub QueryReader(ByV al 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.Str ingBuilder(BufL en)
Dim nSize As Integer = Buffer.Capacity
Try

hInternet = InternetOpen("R FID Monitor",
INTERNET_OPEN_T YPE_DIRECT, vbNullString, vbNullString, 0)
hConnect = InternetConnect (hInternet, strIPAddress, intPort, "",
"", INTERNET_SERVIC E_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_R ELOAD, 0)
bRes = HttpSendRequest (hRequest, vbNullString, 0, 0, 0)

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

bRes = InternetReadFil e(hRequest, Buffer, nSize, lBytesRead)
Console.WriteLi ne(bRes)

Dim myEx As New Win32Exception( bRes)
Console.WriteLi ne(myEx.Message )
Console.WriteLi ne(myEx.ErrorCo de)
Console.WriteLi ne(myEx.HelpLin k)
Console.WriteLi ne(myEx.Source)

If lBytesRead > 0 Then
Dim cmd As New
SqlClient.SqlCo mmand("UpdateRF IDInformation", AT)
cmd.CommandType = CommandType.Sto redProcedure
With cmd
strData.Trim()
strData.Replace ("<?xml version='1.0'?> ", "")
strData.Replace ("'", Chr(34))

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

End If

Catch ex As Exception
EventLog1.Write Entry(ex.Messag e)
Finally
bRes = InternetCloseHa ndle(hInternet)

End Try
--
Cheri Reed
Nov 21 '05 #1
3 3707
"Cheri Reed" <Ch*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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*******@disc ussions.microso ft.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.134 4%40cpmsftngxa0 6.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
4390
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 files containing some templates: adjacency_list.hpp and mem_fn.hpp can not compile. Does anyone have any solutions?
5
16268
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 Server might not be running or the path exists and is redirected to another machine. Please check the status of this virtual directory in the Internet Services Manager."
1
6376
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
6626
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
5039
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. I created the websetup and built the MSI, have the bundled version. Copied to webserver and ran Websetup.msi. Said I had to remove old version, which I did, then reran WebSetup.msi and keeps giving me this error. "The installer was interrupted...
2
955
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, typing "http://192.168.1.254/cgi-bin/dataProxy?oper=queryEvents&raw=1" into IE returns this XML String: <?xml version="1.0" ?>
1
2314
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 could read the whole file and split into an arry, but how do I split on a CRLF ? Mark
2
19510
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
2897
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 will be writing this article intended for those who are in the same level, or maybe lower, of my technical knowledge. I would be using layman's words, or maybe, my own words as how I understand them, hoping, you will understand it the same way that...
0
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9738
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10665
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10723
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9501
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5921
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3177
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.