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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Transfer PDF between servers using HTTP POST

Status
Not open for further replies.

ToddWW

Programmer
Mar 25, 2001
1,073
US
Hello All. I've been working on this for a few days now, scouring the internet and this site for some solutions. I need to be able to move a PDF from one ASP server to another ASP server (not client to server) using HTTP POST. FTP is not an option becuase I need a synchronous transaction with an HTTP response from the receiving server. Here's what I have so far.

SENDING SERVER
Code:
fileName = "c:\temp\testread.pdf"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set theFile = objFso.OpenTextFile(fileName,1,False,0)
strFile = theFile.ReadAll
theFile.Close
Set theFile = Nothing
Set objFso = Nothing

Set objHttp = Server.CreateObject("WinHttp.WinHttprequest.5")
objHttp.Open "POST","[URL unfurl="true"]http://myserver.com/portal/testfiles/test2.asp",False[/URL]
objHttp.Send(strFile)
Response.Write objHttp.ResponseText
Set objHttp = Nothing

RECEIVING SERVER
Code:
binData = Request.BinaryRead(Request.TotalBytes)
FOR i = 1 TO LenB(binData)
	strFile = strFile + Chr(AscB(MidB(binData,i,1)))
NEXT
		
fileName = "c:\temp\testresult2.pdf"
Set objFso = Server.CreateObject("Scripting.FileSystemObject")
Set theFile = objFso.CreateTextFile(fileName,True,False)
theFile.Write(strFile)
theFile.Close
Set theFile = Nothing
Set objFso = Nothing

This works great with text files. But when I try it with a PDF, most of the file makes it fine, but parts of it are corrupted. I've tried different binary conversions, request header options, etc.. But I can't find a single simple solution. I feel there's gotta be something simple out there.

Thanks in advance.

ToddWW
 
Thanks Chris. This looks like it is designed for client to server file uploads. Any idea on server to server using a server object like winhttprequest?
 
You build a HTTP post request on server A which is the client using the server XMLHTTP Object.

Basically the same as an AJAX POST request.


Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top