HTTP Web Request in FoxPro?

HTTP Web Request in FoxPro?

Post by cj » Fri, 10 Aug 2007 21:56:01



We're using VFP 8 and I would like to be able to submit an http request
to a web site. I can do this in Visual Basic but I don't know how in
VFP. Can someone give me some help please?
 
 
 

HTTP Web Request in FoxPro?

Post by Dan Freema » Sat, 11 Aug 2007 00:45:38

How would you do it in VB?

What have you tried so far?

Dan

 
 
 

HTTP Web Request in FoxPro?

Post by cj » Sat, 11 Aug 2007 03:21:13


Dan Freeman wrote:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim URL As String
Dim webReq As Net.HttpWebRequest
Dim webResp As Net.HttpWebResponse
Dim respStr As String

Dim startTime As DateTime
Dim finishTime As DateTime

Try
'test address to verify
URL =
"http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%"
& _
"20USERID=""MYID""><Address ID=""0""><Address1></Address1>" & _
"<Address2>6406 Ivy
Lane</Address2><City>Greenbelt</City><State>MD</State>" & _
"<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>"

webReq = Net.HttpWebRequest.Create(URL)
webReq.Timeout = 5000

startTime = Now
webResp = webReq.GetResponse
finishTime = Now

respStr = New
IO.StreamReader(webResp.GetResponseStream).ReadToEnd
Catch ex As Exception
MessageBox.Show("ex.Message = " & ex.Message)
Finally
webResp.Close()
End Try

'verify actual xml returned
TextBox1.Text = respStr

'response time test
Label1.Text = "Time: " & finishTime.Subtract(startTime).ToString

Dim doc As New Xml.XmlDocument

doc.LoadXml(respStr)

Dim mFirmName As String
If doc.GetElementsByTagName("FirmName").Count = 0 Then
mFirmName = ""
Else
mFirmName =
doc.GetElementsByTagName("FirmName").ItemOf(0).InnerText
End If

Dim mAddress1 As String
If doc.GetElementsByTagName("Address1").Count = 0 Then
mAddress1 = ""
Else
mAddress1 =
doc.GetElementsByTagName("Address1").ItemOf(0).InnerText
End If

Dim mAddress2 As String =
doc.GetElementsByTagName("Address2").ItemOf(0).InnerText
Dim mCity As String =
doc.GetElementsByTagName("City").ItemOf(0).InnerText
Dim mState As String =
doc.GetElementsByTagName("State").ItemOf(0).InnerText
Dim mZip5 As String =
doc.GetElementsByTagName("Zip5").ItemOf(0).InnerText
Dim mZip4 As String =
doc.GetElementsByTagName("Zip4").ItemOf(0).InnerText

Dim mReturnText As String
If doc.GetElementsByTagName("ReturnText").Count = 0 Then
mReturnText = ""
Else
mReturnText =
doc.GetElementsByTagName("ReturnText").ItemOf(0).InnerText
End If

TextBox3.Text = mFirmName & vbCrLf & _
mAddress1 & vbCrLf & _
mAddress2 & vbCrLf & _
mCity & ", " & _
mState & " " & _
mZip5 & "-" & _
mZip4 & vbCrLf & _
mReturnText & vbCrLf
End Sub

Nothing, I have no clue if anything like this can be done in VFP.


 
 
 

HTTP Web Request in FoxPro?

Post by Dan Freema » Sat, 11 Aug 2007 04:22:17

K, looks like you're *actually* asking about retrieving information from an
XML web service. While technically the same thing, there really is a
difference. <g>

In this case, the difference works in your favor. Have a look at the
_ws3clent.vcx classes in Foxpro's FFC directory. They're wrapper classes for
handling web services. Once you have your response you can certainly load it
into a parser as you're doing here, or you can use XMLtoCursor() or an
XMLAdapter to read the data.

Dan


cj wrote:


 
 
 

HTTP Web Request in FoxPro?

Post by cj » Sun, 12 Aug 2007 05:15:16

have a file _ws3client.vcx but what do I do with it?

I've found this tutorial

http://www.west-wind.com/presentations/xmlmessaging/soapwebservices.htm

It wants me to do

oHTTP=CREATEOBJECT("wwHTTP")

but this doesn't work as such for me. I assume I need to add wwHTTP
into my program some how. How?



Dan Freeman wrote:
 
 
 

HTTP Web Request in FoxPro?

Post by Dan Freema » Sun, 12 Aug 2007 06:39:23

'm sorry -- I didn't realize you're not familiar with Foxpro at all.

_ws3client.vcx is a visual class library. You'd explore it either with the
class browser or class designer.

wwHTTP is a class written by Rick Strahl (owner at www.west-wind.com) and is
available in his products.

The easiest way for you to get started is to get the WSDL address for the
service you want to use, and then register it in the VFP Toolbox. Once it's
registered you can drag/drop the service into any code window and VFP will
write the code needed to connect, *and* hook up all supported methods as
intellisense prompts.

Dan

cj wrote:


 
 
 

HTTP Web Request in FoxPro?

Post by cj » Tue, 14 Aug 2007 22:14:20

SPS doesn't offer a wsdl.

I don't want to mess with another add on package unless FoxPro itself
can't do this so I guess I'll pass on west wind.

Skipping all the parsing of the xml in my vb code that boiled down to 3
lines.

URL =
"http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<AddressValidateRequest%"
& _
"20USERID=""MYID""><Address ID=""0""><Address1></Address1>" & _
"<Address2>6406 Ivy
Lane</Address2><City>Greenbelt</City><State>MD</State>" & _
"<Zip5></Zip5><Zip4></Zip4></Address></AddressValidateRequest>"

webReq = Net.HttpWebRequest.Create(URL)

webResp.GetResponseStream


I would like to do this in a button on my foxpro form. I'm not sure
what to ask you. I found that class brower and looked at _ws3client.vcx
but couldn't figure out what I was seeing.




Dan Freeman wrote:
 
 
 

HTTP Web Request in FoxPro?

Post by cj » Wed, 15 Aug 2007 00:07:03

verything I'm finding seems to suggest that VFP will not work unless
they provide a WSDL, which they don't. I'm hoping you can prove me wrong.

Dan Freeman wrote:
 
 
 

HTTP Web Request in FoxPro?

Post by Dan Freema » Wed, 15 Aug 2007 00:40:47

et's look at what you're really using in VB:

Net.HttpWebRequest

This is ****NOT**** part of VB! It is an external class supplied by the .NET
framework.

There are external classes supplied by Win32 as well. I believe if you'll
look at MSXML you'll find an object that will do your post.

I'd give you an example if I could but its been almost 10 years since I last
fiddled with it. I have trouble remembering what I had for lunch yesterday.
<g>

Dan

cj wrote:


 
 
 

HTTP Web Request in FoxPro?

Post by Anders Alt » Wed, 15 Aug 2007 02:25:25

here's a free class for HTTP
http://www.west-wind.com/wwXML.asp

-Anders

"cj" < XXXX@XXXXX.COM > wrote in message
news:% XXXX@XXXXX.COM ...

 
 
 

HTTP Web Request in FoxPro?

Post by swdev » Wed, 15 Aug 2007 12:38:42

ook here for sample code -
http://fox.wikis.com/wc.dll?Wiki~ProFoxWebServices~VFP

it's a bit old, not even sure if the Profox server is still up ,
but -
you'll see an example of how to write the code.

HTH - Regarsd [Bill]
"cj" < XXXX@XXXXX.COM > wrote in message
news: XXXX@XXXXX.COM ...
the
and is
the
it's
will
"http://testing.shippingapis.com/ShippingAPITest.dll?API=Verify&XML=<Address
ValidateRequest%"
startTime


 
 
 

HTTP Web Request in FoxPro?

Post by cj » Thu, 16 Aug 2007 00:52:30

saw that a day or so ago but all the code seems to depend on loading a
wsdl file. They don't provide a wsdl file.

swdev2 wrote:
 
 
 

HTTP Web Request in FoxPro?

Post by Jeroen van » Thu, 16 Aug 2007 03:32:03

n Thu, 09 Aug 2007 14:21:13 -0400, cj < XXXX@XXXXX.COM > wrote:

Well, it is not that hard to do a GET or a POST against a website.
There are some nice com-libraries available.
Try:

loInternet=CreateObject("MSXML2.ServerXMLHTTP")
loiNTERNET.setTimeouts(60000,10000,60000,60000)
IF EMPTY(lcPostdata)
loInternet.open([GET],lcURL)
ELSE
loInternet.open([POST],lcURL)

l.oInternet.setRequestHeader([Content-Type],[application/x-www-form-urlencoded])
ENDIF
loInternet.send(lcPostData)
lcPage=loInternet.responseBody

Be aware that this is a special 'server-xml' component, so that any
special settings in the request header have to be done yourself.
Like e.g. setting cookies, refererstring



 
 
 

HTTP Web Request in FoxPro?

Post by cj » Fri, 17 Aug 2007 05:24:04

hat is lcpostdata? That gives me an error when I try to use this.

Jeroen van Kalken wrote:
 
 
 

HTTP Web Request in FoxPro?

Post by Jeroen van » Fri, 17 Aug 2007 08:31:40

n Tue, 14 Aug 2007 20:32:03 +0200, Jeroen van Kalken
< XXXX@XXXXX.COM > wrote:

lcPostData is a variable which contains the charcters to 'POST' to the
website.If is is empty, then a 'GET' request is used to the website.
In your example you use a get-request with al the info in the URL,
therefore you can just initialise the lcPostData to an empty string.