Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Internet Transfer Control: not all data coming back 2

Status
Not open for further replies.

nathj

Programmer
Oct 11, 2004
33
GB
I am currently developing a system to retrieve data from a 3rd party server. The server requires a standard message to be posted to it.

So far I am posting the message using Microsoft Internet Transfer Control from a Visual FoxPro 6 application. The POST works and the connection is fine with no timeouts. It simply doesn't get all the required data, the returned file cuts out at 4Kb.

Can anyone help. the only restriction to any solutions is that I cannot up grade to a newer version of FoxPro.
 
Sorry about this I meant to add the code sample into the first post but I forgot. I do aopologise. anyway here it is:
cToPost = filetostr("c:\temp\autoconnecttest\fidelmsg.txt")
cURL = "
WITH ThisForm.Olecontrol1
.protocol = 5
.URL = cURL
.execute(, "POST", cToPost, )
*!* cResult = .openURL()
*!* strtofile(cresult, "c:\temp\autoconnecttest\fidelresult.txt")
ENDWITH

this is executed on the click event of a button on a form. the form has the ITC object on it. the file returned is not complete is there a way of changing this. When the data is returned it is to a tring and then to a file from that using strtofile() .

Any help is welcome.
Nathan
 

It might be useful if you posted the code you are using to download the files, as it seems that is where the problem lies.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Sure thing, after the click event is executed the ITC objects statechange event is invoked and this looksa like:
*** ActiveX Control Event ***
LPARAMETERS state
? state
IF state = 12
myChr = THIS.getheader()
STRTOFILE(myChr, "c:\temp\autoconnecttest\fidelhdr.txt")
mystr = THIS.getchunk(10000000, 0)
STRTOFILE(mystr, "c:\temp\autoconnecttest\fidelResponse1.txt")
*- string manipulation
mystr = SUBSTR(mystr, AT("<ReportData>", mystr) + 12, ;
AT("</ReportData>", mystr) - (AT("<ReportData>", mystr) + 12))
mystr = STRTRAN(mystr, "<DataRow>", "")
mystr = STRTRAN(mystr, "</DataRow>", CHR(13))
mystr = STRTRAN(mystr, "&quot", "")
mystr = STRTRAN(mystr, ";", "")
STRTOFILE(mystr, "c:\temp\autoconnecttest\fidelResponse2.txt")
WAIT WINDOW " It's done " NOWAIT
ENDIF
Thanks for stopping by and helping out.
 

I'm wondering why the "*!* cResult = .openURL()" is commented and why it would appear after you try to post. Don't you need to open the URL before you can post?


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike
The code sample is from a development/test area on my pc and the commented out lines are commented out because they are previous failed attempt. I should also explain the string manipulation. The returned file is a CSV data set embedded in an XML file. So it simply removes all the tags and extra buits and bobs leaving me with just the csv file.

I was not ware of the need to open the URL before POSTing. I will give this a try and post back to let you know how I get on.

Many thanks
Nathan
 
Hi Mike,

I have tried the code with the openURL call beofre the execute command and there is no difference in the behaviour.

Any other sugeestions?

Nathan
 
Nathan

Here is an example (without the file download part) that confirms to proper connection.
Code:
PUBLIC ofrminetcontrol
ofrminetcontrol=NEWOBJECT("frminetcontrol")
ofrminetcontrol.Show
RETURN
DEFINE CLASS frminetcontrol AS form
	Top = 0
	Left = 0
	Height = 417
	Width = 546
	DoCreate = .T.
	Caption = "Demonstrate the Internet Transfer Control"
	chtml = ""
	Name = "frmInetControl"
	ADD OBJECT oleinetcontrol AS olecontrol WITH ;
		Top = 360, ;
		Left = 456, ;
		Height = 100, ;
		Width = 100, ;
		Name = "oleInetControl", ;
		OleClass = 'InetCTLS.Inet.1'
	ADD OBJECT cmddoit AS commandbutton WITH ;
		Top = 348, ;
		Left = 52, ;
		Height = 27, ;
		Width = 84, ;
		Caption = "Get it", ;
		TabIndex = 7, ;
		Name = "cmdDoIt"
	ADD OBJECT txturl AS textbox WITH ;
		Height = 23, ;
		Left = 52, ;
		TabIndex = 2, ;
		Top = 12, ;
		Width = 443, ;
		Name = "txtURL"
	ADD OBJECT edthtml AS editbox WITH ;
		Height = 120, ;
		Left = 52, ;
		TabIndex = 4, ;
		Top = 60, ;
		Width = 444, ;
		ControlSource = "ThisForm.cHtml", ;
		Name = "edtHTML"
	ADD OBJECT lblurl AS label WITH ;
		Caption = "URL", ;
		Height = 17, ;
		Left = 3, ;
		Top = 16, ;
		Width = 24, ;
		TabIndex = 1, ;
		Name = "lblURL"
	ADD OBJECT lblhtml AS label WITH ;
		AutoSize = .T., ;
		Caption = "HTML", ;
		Height = 17, ;
		Left = 3, ;
		Top = 62, ;
		Width = 34, ;
		TabIndex = 3, ;
		Name = "lblHTML"
	ADD OBJECT edtheaders AS editbox WITH ;
		Height = 120, ;
		Left = 52, ;
		TabIndex = 6, ;
		Top = 205, ;
		Width = 444, ;
		Name = "edtHeaders"
	ADD OBJECT label1 AS label WITH ;
		AutoSize = .T., ;
		Caption = "Headers", ;
		Height = 17, ;
		Left = 0, ;
		Top = 207, ;
		Width = 50, ;
		TabIndex = 5, ;
		Name = "Label1"
	PROCEDURE Load
		IF "5.0" $ VERSION()
			SYS(2333,0)
		ENDIF
	ENDPROC
	PROCEDURE cmddoit.Click
		ThisForm.cHTML = ThisForm.OleInetControl.Object.OpenURL(TRIM(ThisForm.TxtURL.Value))
		ThisForm.edtHeaders.Value = ThisForm.oleInetControl.Object.GetHeader()
		Thisform.Refresh()
	ENDPROC
ENDDEFINE


Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi again and thanks for the code sample I have had a look through this and tested it out with the URL I am trying to POST to. The result comes back and it says the server only responds to POST.
This object is fairly new to me and I'm not overly familiar with what it can and can't do. Is there any way to use the POST verb wothout the apparent file restriction of 4Kb?

Nathan
 

I'm not too familiar with ITC Activex. I tend to avoid the as best as I can. I'm more familiar with using FTP transfers. Perhaps faq184-4359 might help. If you subscribe to FoxPro Advisor, the issue of August 2000 there was an article on Internet Transfert Control.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Hi Mike,

I'll wrk through that article it looks really helpful.

thanks for all your help and time on this one it's really appreciated. I must admoit I prefere ftp stuff but the choice is unfortuantely not mine to make.

Cheers
Nathan
 
I'm not familiar with the ActiveX component you're using but we use http posts quite a bit using the following COM object. The server typically returns data embedded in XML tags and I have been bitten several times with embedded ASCII escape characters in the data fields that were returned. Particularly when attempting to direct the response text to a cursor or file. Don't know if this pertains to your problem but I have seen a response stream prematurely terminated because of an escape char.

Code:
cToPost = filetostr("c:\temp\autoconnecttest\fidelmsg.txt")
cURL = "[URL unfurl="true"]https://www.reportingservices.fidelity.co.uk/ukrep/Reporti..."[/URL]

loHTTP = CREATEOBJECT("WinHttp.WinHttpRequest.5.1")
* or "WinHttp.WinHttpRequest.5" depending on dll version
loHTTP.Open("POST", cURL , .F.)
loHTTP.SetRequestHeader("content-type", "application/x-[URL unfurl="true"]www-form-urlencoded")[/URL]
lohttp.Send()
?  LEN(loHTTP.ResponseText)
STRTOFILE(loHTTP.ResponseBody, cToPost)

Good luck

Ralph
 
Hi Ralph,

I've had a go with that code and it does look like we could be getting somewhere. The interesting thing now is the response comes back as follows:

<?xml version="1.0" encoding="UTF-8"?>
<ReportingServicesResponse><ErrorList>1005</ErrorList><ErrorList>The root element is required in a well-formed document.</ErrorList></ReportingServicesResponse>

The message that is being posted looks like this:

<?xml version='1.0' encoding='UTF-8' ?>
<RequestList>
<InformationRequest UserId='xxxxxxxx' PIN='xxxx' reportType='IFA-H2' VendorVersionIdentifier='Fairs Software' />
</RequestList>

this is just being read in from a file to a string in order to post it. does this need to be loadded into some kind of container object? Or is there something else I am missing?

Many thanks
Nathan
 
I believe FileToStr() should work. I'ld try looking at the contents of the variable in the debugger to ensure that you've got the entire XML.

Is the server expecting to set authorization from the XML or do you need to pass it in the post?
If you're using the COM try the following before calling the send method.
Code:
loHttp.SetCredentials(lcUserName, lcPIN, 0)

I'm not an XML expert but what you're posting looks fine to me. I actually just submitted your XML post to that server and got the following response as you would expect.

<?xml version="1.0" encoding="UTF-8"?>
<ReportingServicesResponse><ErrorList>1000</ErrorList><ErrorList>Login failure </ErrorList></ReportingServicesResponse>

Earlier I submitted a blank post and got the same response you listed above which initially seems to suggest that your stream wasn't submitted correctly. Maybe check the content of your variable before you send.

Ralph
 
I just re-read my earlier posting and noticed that the line to send should have read:

Code:
lsToSend = FileToStr("XmlToPost.txt")
loHttp.Send( lsToSend )

Sorry if that omission caused any confusion.

Ralph
 
Ralph,
I have tried that and now I get the correct results back!

You are truley a star!

I owe you one!

Nathan
 
Nathan,

That's great and thanks for the star. Using this COM object is an elegant solution, MS did us FoxPro people a favor by providing it. A couple of things in case you should encounter them. The COM allows you to set the timeouts if needed. It also allows you to make proxy server settings should the user's environment require it. It is also one of the few solutions I found that allow passing client certificates which was one of the big requirements I had in passing confidential data by http. All in all a pretty versitile tool.


Ralph
 
Hi Ralph,
thanks again for your help yesterday I have now moved the code into the application and it all seems to be working great. I have one final question., what dll is this using? As we need to ensure that the various dll's will be available to our end user and I thought you might know; is it winhttp.dll or winhttp5.dll or something else?

Cheers
Nathan
 
Sorry for the delay in repsonding to you but I was a little tied up yesterday and didn't get my recommended daily dose of Tek-Tips. There are 2 versions of the dll you can use: WinHttp.dll (version 5.1) and WinHttp5.dll (version 5). The code uses version 5.1 which is a standard component of Win 2K SP3 and XP. In fact if you attempt to install the dll on an XP machine you should get a warning that it is a protected component. For more
info:
Ralph
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top