Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    Visual Basic




Upload File To HTTP With WININET PUT


Hi Guys

I know that this topic has been raised repeatedly on the forums, but none of them have a resolution as of yet. I'm hoping someone will help me on this...

I'm trying to write an automatic downloading utility for my application. The app on the Client machine should compose an XML document of all of the custom OCX's and DLL's with their versions, as well as serial codes for the licensing of these files.

Once the file has been compiled ( or created or generated or whatever ) I wish to send this file to the Web Server. I've completed ALL of the steps, except the sending to the Web Server.

I need to use HTTP, as certain ISP's for my clients do not allow FTP access. Also, I wish to use the PUT method because I cannot send large files using POST. (My file will average at about 100KB)

ANY HELP would be appreciated.

PS: I will upload my code samples sometime when I'm done looking at them... a few things to sort out first




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
VB Client Fails To Upload Simulated HTTP File Upload Requests > 32 KB Via SSL
Goal: Upload binary file(s) and data from custom VB client to pure ASP upload script via HTTPS

Info: Upload from html page seems to work fine. When uploading from VB client, connection times out if request size is over 32 KB limit and no response is received. Seems to work for requests less than 32 KB ...

Requirements: HTTPS, multiple binary files and data, pure ASP upload script, custom VB client

Question: What am I missing? This project is now 3 weeks over due and I can't figure out what is wrong. I am using code from 3 different samples/articles available on line (I don't remember where) ... The client application uses a winsock control, using ssl encryption, and constructs a request packet duplicating the "post" method of an html file upload page. I assumed that any file size could be uploaded, as is evident from using an html form. Is there something a browser does with large requests to get the server to accept requests larger than 32KB?

I am not sure which part of the code needs to be reviewed ... I will supply required code as needed (http request simulation, SSL encryption, or winsock functions).

About Upload File Use Wininet API
Dear sir/madam:
I have written some codes to implement upload file wit5h big size,but it can't work,why?please give me a hand,thanks anyway!

/////////////////the code///////////////// http://support.microsoft.com/suppor...s/Q184/3/52.ASP

Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, _
ByVal lAccessType As Long, ByVal sProxyName As String, _
ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetConnect Lib "wininet.dll" _
Alias "InternetConnectA" (ByVal hInternetSession As Long, _
ByVal sServerName As String, ByVal nServerPort As Integer, _
ByVal sUsername As String, ByVal sPassword As String, _
ByVal lService As Long, ByVal lFlags As Long, _
ByVal lContext As Long) As Long
Private Declare Function HttpOpenRequest Lib "wininet.dll" Alias "HttpOpenRequestA" _
(ByVal hHttpSession As Long, ByVal sVerb As String, ByVal sObjectName As String, ByVal sVersion As String, _
ByVal sReferer As String, ByVal something As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Private Declare Function HttpSendRequest Lib "wininet.dll" Alias "HttpSendRequestA" (ByVal _
hHttpRequest As Long, ByVal sHeaders As String, ByVal lHeadersLength As Long, ByVal sOptional As String, ByVal lOptionalLength As Long) As Integer

Private Declare Function InternetWriteFile Lib "wininet.dll" _
(ByVal hFile As Long, ByVal sBuffer As Long, _
ByVal lNumberOfBytesToRead As Long, _
lNumberOfBytesRead As Long) As Integer

Private Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Private Const INTERNET_OPEN_TYPE_DIRECT = 1
Private Const INTERNET_OPEN_TYPE_PROXY = 3


Private Const INTERNET_INVALID_PORT_NUMBER = 0 '// use the protocol-specific default

Private Const INTERNET_DEFAULT_FTP_PORT = 21 ' // default for FTP servers
Private Const INTERNET_DEFAULT_GOPHER_PORT = 70 ' // " " gopher "
Private Const INTERNET_DEFAULT_HTTP_PORT = 80 ' // " " HTTP "
Private Const INTERNET_DEFAULT_HTTPS_PORT = 443

Private Const INTERNET_SERVICE_URL = 0
Private Const INTERNET_SERVICE_FTP = 1
Private Const INTERNET_SERVICE_GOPHER = 2
Private Const INTERNET_SERVICE_HTTP = 3

Private Const INTERNET_FLAG_NO_CACHE_WRITE = &H4000000


Private Const HSR_ASYNC = &H1 ' // force async
Private Const HSR_SYNC = &H4 ' // force sync
Private Const HSR_USE_CONTEXT = &H8
Private Const HSR_INITIATE = &H8 ' // iterative operation (completed by HttpEndRequest)
Private Const HSR_DOWNLOAD = &H10 ' // download to file
Private Const HSR_CHUNKED = &H20 ' // operation is send of chunked data



Private Const BUFFSIZE = 500

Private Type INTERNET_BUFFERS
dwStructSize As Long
Next As Long
lpcszHeader As Long
dwHeadersLength As Long
dwHeadersTotal As Long
lpvBuffer As Long
dwBufferLength As Long
dwBufferTotal As Long
dwOffsetLow As Long
dwOffsetHigh As Long
End Type

Private Declare Function HttpSendRequestEx Lib "wininet.dll" Alias "HttpSendRequestExA" (ByVal hRequest As Long, ByVal lpBuffersIn As Long, ByVal lpBuffersOut As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function HttpEndRequest Lib "wininet.dll" Alias "HttpEndRequestA" (ByVal hRequest As Long, lpBuffersOut As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Long
Private Declare Function FillMemory Lib "KERNEL32.DLL" Alias "RtlFillMemory" ( _
Destination As Any, _
ByVal Length As Long, _
Fill As Byte) As Long
Private Type SECURITY_ATTRIBUTES
nLength As Long
lpSecurityDescriptor As Long
bInheritHandle As Long
End Type
Private Declare Function CreateFile Lib "kernel32" _
Alias "CreateFileA" _
(ByVal lpFileName As String, _
ByVal dwDesiredAccess As Long, _
ByVal dwShareMode As Long, _
ByVal lpSecurityAttributes As Long, _
ByVal dwCreationDisposition As Long, _
ByVal dwFlagsAndAttributes As Long, _
ByVal hTemplateFile As Long) _
As Long
Private Const GENERIC_READ = &H80000000
Private Const FILE_SHARE_READ = &H1

Private Const OPEN_EXISTING = 3

Private Const FILE_ATTRIBUTE_NORMAL = &H80

Private Const INVALID_HANDLE_VALUE = -1
Private Declare Function GetFileSize Lib "kernel32" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
Private Type OVERLAPPED
Internal As Long
InternalHigh As Long
offset As Long
OffsetHigh As Long
hEvent As Long
End Type

Private Declare Function ReadFile Lib "kernel32" (ByVal hFile As Long, lpBuffer As Any, ByVal nNumberOfBytesToRead As Long, lpNumberOfBytesRead As Long, ByVal lpOVERLAPPED As Long) As Long
Private Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long



Private Sub PostFile(strServer As String, strLocalFile As String, strURL As String, Optional strUser As String, Optional strPass As String)
Dim hSession, hConnect, hRequest As Long

hSession = InternetOpen("HttpSendRequestEx", INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, 0)
If hSession = 0 Then
Exit Sub
End If
hConnect = InternetConnect(hSession, strServer, INTERNET_DEFAULT_HTTP_PORT, strUser, strPass, INTERNET_SERVICE_HTTP, 0&, 0&)
If hConnect = 0 Then
Exit Sub
End If
hRequest = HttpOpenRequest(hConnect, "POST", strURL, vbNullString, vbNullString, 0&, INTERNET_FLAG_NO_CACHE_WRITE, 0)
If hRequest Then
Call UseHttpSendReqEx(hRequest, strLocalFile)
End If
Call InternetCloseHandle(hRequest)
Call InternetCloseHandle(hConnect)
Call InternetCloseHandle(hSession)
End Sub

Private Function UseHttpSendReqEx(hRequest As Long, strUpFile As String) As Boolean

Dim BufferIn As INTERNET_BUFFERS
Dim BufferOut As INTERNET_BUFFERS
Dim pp As INTERNET_BUFFERS
Dim res As Long
Dim dwBytesWritten As Long
Dim MaxTimes As Integer
Dim pBuffer(1024) As Byte
Dim bRet As Boolean
Dim lngReservedSize As Long
Dim hFile As Long
Dim Sum As Long
Dim bRead As Long
Dim lpSA As SECURITY_ATTRIBUTES
Dim lpOVERLAPPED As OVERLAPPED
Dim lngFileSize As Long

hFile = CreateFile(strUpFile, GENERIC_READ, FILE_SHARE_READ, 0&, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0&)


If hFile = INVALID_HANDLE_VALUE Then
MsgBox "Error to open Upfile!"
Exit Function
End If
lngFileSize = GetFileSize(hFile, 0&)

BufferIn.dwStructSize = Len(INTERNET_BUFFERS)
BufferIn.dwBufferTotal = lngFileSize
BufferIn.dwBufferLength = 0
BufferIn.dwHeadersLength = 0
BufferIn.dwHeadersTotal = 0
BufferIn.dwOffsetHigh = 0
BufferIn.dwOffsetLow = 0
BufferIn.lpcszHeader = 0&
BufferIn.lpvBuffer = 0&
BufferIn.Next = 0&

res = HttpSendRequestEx(hRequest, VarPtr(BufferIn), VarPtr(BufferOut), HSR_INITIATE, 0&)
If res = 0 Then
MsgBox "error to HttpSendRequestEx!"
Exit Function
End If


Sum = 0
Do

bRead = ReadFile(hFile, pBuffer(0), 1024, dwBytesRead, 0&)

If bRead = 0 Then
MsgBox "Error Read File!"
Exit Function
End If


bRet = InternetWriteFile(hRequest, VarPtr(pBuffer(0)), dwBytesRead, dwBytesWritten)
If bRet = False Then
MsgBox "Error InternetWrite File!"
Exit Function
End If
Sum = Sum + dwBytesRead

Loop Until Sum = lngFileSize

Call CloseHandle(hFile)



Call HttpEndRequest(hRequest, 0&, 0, 0)


End Function

Private Sub Command1_Click()
Call PostFile("127.0.0.1", "c:
etlog.txt", "/test.htm")
End Sub


///////////////////////end of code///////

if you find the answer,please contact with me,my email is Qixh@neusoft.com,thanks again!

Empty File In WinInet FTP Upload?
Hi Newbie Here, I'm having problem with my program. Im doing FTP Upload using
WinInet in vb6 but the problem is when I upload the file it is zero filesize or empty. Please help with my problem.


Thanks a lot

Upload File To HTTP
Hello

Im interested to send and file to and URL.

Example
http://www.domain.com/new.php?file={HERE THE CODE OF FILE}


Can you help me?

I dont like ftp but is slow I need send by post of a HTTP URL.

Thanks

Upload File Via HTTP??
Hey again!

I was wondering how i might achieve this? I have a PHP Script ready, that will accept the upload, parse, and store a .LUA file into a database, and then put the data out using Java later on. .LUA is a programming language used to interface into video games, to make addons, and stuff. So it's a text file.

Could someone throw me a little insight on how to upload via http to a php script? I've searched a bit, but most of the time i see people just saying "ooo just use ftp boo boo" and what not, that would not suit me, as i need the file parsed using my luaparser.php to parse the information throughout the file.


So could someone please help me out here? Thanks!!!

Http File Upload
hi...am fairly new in vb..so i have a problem
i need to upload a file to a http server....have tried inet ctl n winsock but it doesnt seem to work...the prog has to be such that it works in the background n without using any external help..ie a third party......
plz its kinda urgent so it'll be really good if u provide me with a solution
thnx

Upload And Download File Using HTTP
I wish to upload and download files to a webserver. Is there any free dll or module class that offered the upload and download functionality to and from HTTP that we can make use of?

Upload And Download File Using HTTP
I wish to upload and download files to a webserver. Is there any free dll or module class that offered the upload and download functionality to and from HTTP that we can make use of?

Upload And Download File Using HTTP
I wish to upload and download files to a webserver. Is there any free dll or module class that offered the upload and download functionality to and from HTTP that we can make use of?

Upload A File Using Http Protocol
Can I upload a file to a web site using http protocol.
I mean, like using OpenUrl command of Internet transfer object to download, something to put the file back on the web, but not using ftp protocol?
thanks

Upload A File To A Http:// Site
using inet1 how do you send a file to a http web site i need to send customer info to the server but theres no ftp site only an http:// site ???

Upload A File On Web Server Using Http
Hello,

I want to upload any file from my client
application (running on Win32 Platform) to a web
server (let say IIS).
How can I do this using http? I don't want to use
ftp. I want to develop this as independent VB COM
Component.
I am using Visual Basic 6.

Can Anybody help me on this? It will be great If
u can attach running VB Code with your answer.

Thank you.

Problems With Http Form File Upload
Hello,

What I want to do is:
Make a program that inputs a file, and upload it to a html form on a server somewhere else (through the file upload control on the html form)

I did my homework, and found out its not THAT difficult, I just have to connect to the server through a winsock, and send something like this:
(more info about this can be found in RFC 1867 "Form-based File Upload in HTML")


Code:
-----------------------------7d01ecf406a6
Content-Disposition: form-data; name="fileupload";
filename="C:pic.gif"
Content-Type: image/gif

<HERE GOES THE FILE CONTENT>
-----------------------------7d01ecf406a6--

Now, I got this working... kinda...
If I do something like this (pseudocode) it works fine:


Code:
dim FileContent as string
FileContent = GetFileContent("c:pic.gif")
Winsock.SendData Header_Part1 & FileContent & Header_Part2

As you see, this is not very good for large files... because they are loaded into the ram first, and then sent in one massive send.
So I wanted to upload it in chunks using a buffer.

Problem is, I get disconnected as soon as I send the second part.
I did some debugging, and found out even this does not work:


Code:
dim FileContent as string
FileContent = GetFileContent("c:pic.gif")
Winsock.SendData Header_Part1
Winsock.SendData FileContent
Winsock.SendData Header_Part2

On the second send the server returns an "501 Method Not Implemented" error, which is logical since it sees the second send as a new command, and does not recognize it.

So my question is, can I somehow upload my file to the server in multiple pieces, so i can read a bit, upload it, read a bit, upload it, ...?

Reinout.

Winsock Control - Http File Upload
Hi All

I have a program that will have to periodically update a website with files generated by the VB client program. The operation of this is automatic with no user intervention. Additionally I am already using the winsock control throughout the app. I could use a normal FTP operation but that means that each time the program tries to log on the FTP username and password would be sent across then network...

Please post back with any suggestions or comments. They would be appreciated!!!!

TIA
Mike

Http Post File Upload (binary)
know you can do this with ie (html) using a <input type="file" name="attachment">, but i need this functionality in a vb app. do i need to manually do a base64 encode on the file and attach it to a multi-part request or can i call some api/dll/whatever that ie uses?? i am a new vb programmer so please, any help would be greatly appreciated.

Visual Basic / Upload File / Via Http
I am looking to post or put a binary file to an http://server/filename.exe from a folder on my local system such as c:foldernamefilename.exe using visual basic and totally silent so that I can schedule it with the task scheduler. i am new to programming and i am trying to teach myself. but i am stumped. i have been successful at creating an automated download job using inet1. Can any one help? with an example and an syntax explaination

Upload A File From Client To Server Through HTTP
Hi ,

Is there a way i can use winhttp.dll that comes with microsoft in vb to upload a file through HTTP from my client machine to the server.Can it be a secure connection.
Early help apppreciated.

Thanks,
Raji

An Answer How To Upload File Through HTTP With VB &amp; HTML
1. construction of HTML FORM (only important parts of it):

<form method="post" enctype="multipart/form-data" action="[URL2YourVBHere]">
<input type=file name="UplFile">


2. construction of your VB Sub:
(you have to have access to IIS objects, particularly Request in your code - it's quite easy to pass it from asp to VB COM object)

Private Sub GetFileAndSaveIt(Request)
Dim fso As New FileSystemObject 'this is class in Scripting (scrrun.dll)
Dim Uploader As FileUploader 'this is class defined below
Dim File As UploadedFile ''this is class defined below

Set Uploader = New FileUploader
Uploader.Upload Request
Set File = Uploader.Files.Item("UplFile")
File.SaveToDisk "Path2YourDestFolder/"

'that's the way to find out the name of uploaded file:
File.FileName

'that's the way to access other fields of that form:
Uploader.Form("NameAttribOfOtherField")

End Sub


3. here are two class definitions - they do all of the work, you can but not have to analyse it

UploadedFile.cls
Option Explicit

Public ContentType
Public FileName
Public FileData

Public Property Get FileSize()
FileSize = LenB(FileData)
End Property

Public Sub SaveToDisk(sPath)
Dim oFS As New Scripting.FileSystemObject, oFile As TextStream
Dim nIndex

If sPath = "" Or FileName = "" Then Exit Sub
If Mid(sPath, Len(sPath)) <> "" Then sPath = sPath & ""

'Set oFS = Server.CreateObject("Scripting.FileSystemObject")
If Not oFS.FolderExists(sPath) Then Exit Sub

Set oFile = oFS.CreateTextFile(sPath & FileName, True)

For nIndex = 1 To LenB(FileData)
oFile.Write Chr(AscB(MidB(FileData, nIndex, 1)))
Next

oFile.Close
End Sub

Public Sub SaveToDatabase(ByRef oField)
If LenB(FileData) = 0 Then Exit Sub

If IsObject(oField) Then
oField.AppendChunk FileData
End If
End Sub



FileUploader.cls
Option Explicit

Public Files As Scripting.Dictionary
Private mcolFormElem As Scripting.Dictionary

Private Sub Class_Initialize()
Set Files = New Scripting.Dictionary
Set mcolFormElem = New Scripting.Dictionary
End Sub

Private Sub Class_Terminate()
If IsObject(Files) Then
Files.RemoveAll
Set Files = Nothing
End If
If IsObject(mcolFormElem) Then
mcolFormElem.RemoveAll
Set mcolFormElem = Nothing
End If
End Sub

Public Property Get Form(sIndex)
Form = ""
If mcolFormElem.Exists(LCase(sIndex)) Then Form = mcolFormElem.Item(LCase(sIndex))
End Property

Public Sub Upload(Request As Object)
Dim biData, sInputName
Dim nPosBegin, nPosEnd, nPos, vDataBounds, nDataBoundPos
Dim nPosFile, nPosBound

biData = Request.BinaryRead(Request.TotalBytes)
nPosBegin = 1
nPosEnd = InStrB(nPosBegin, biData, CByteString(Chr(13)))

If (nPosEnd - nPosBegin) <= 0 Then Exit Sub

vDataBounds = MidB(biData, nPosBegin, nPosEnd - nPosBegin)
nDataBoundPos = InStrB(1, biData, vDataBounds)

Do Until nDataBoundPos = InStrB(biData, vDataBounds & CByteString("--"))

nPos = InStrB(nDataBoundPos, biData, CByteString("Content-Disposition"))
nPos = InStrB(nPos, biData, CByteString("name="))
nPosBegin = nPos + 6
nPosEnd = InStrB(nPosBegin, biData, CByteString(Chr(34)))
sInputName = CWideString(MidB(biData, nPosBegin, nPosEnd - nPosBegin))
nPosFile = InStrB(nDataBoundPos, biData, CByteString("filename="))
nPosBound = InStrB(nPosEnd, biData, vDataBounds)

If nPosFile <> 0 And nPosFile < nPosBound Then
Dim oUploadFile, sFileName
Set oUploadFile = New UploadedFile

nPosBegin = nPosFile + 10
nPosEnd = InStrB(nPosBegin, biData, CByteString(Chr(34)))
sFileName = CWideString(MidB(biData, nPosBegin, nPosEnd - nPosBegin))
oUploadFile.FileName = Right(sFileName, Len(sFileName) - InStrRev(sFileName, ""))

nPos = InStrB(nPosEnd, biData, CByteString("Content-Type:"))
nPosBegin = nPos + 14
nPosEnd = InStrB(nPosBegin, biData, CByteString(Chr(13)))

oUploadFile.ContentType = CWideString(MidB(biData, nPosBegin, nPosEnd - nPosBegin))

nPosBegin = nPosEnd + 4
nPosEnd = InStrB(nPosBegin, biData, vDataBounds) - 2
oUploadFile.FileData = MidB(biData, nPosBegin, nPosEnd - nPosBegin)

If oUploadFile.FileSize > 0 Then Files.Add LCase(sInputName), oUploadFile
Else
nPos = InStrB(nPos, biData, CByteString(Chr(13)))
nPosBegin = nPos + 4
nPosEnd = InStrB(nPosBegin, biData, vDataBounds) - 2
If Not mcolFormElem.Exists(LCase(sInputName)) Then mcolFormElem.Add LCase(sInputName), CWideString(MidB(biData, nPosBegin, nPosEnd - nPosBegin))
End If

nDataBoundPos = InStrB(nDataBoundPos + LenB(vDataBounds), biData, vDataBounds)
Loop
End Sub

'String to byte string conversion
Private Function CByteString(sString)
Dim nIndex
For nIndex = 1 To Len(sString)
CByteString = CByteString & ChrB(AscB(Mid(sString, nIndex, 1)))
Next
End Function

'Byte string to string conversion
Private Function CWideString(bsString)
Dim nIndex
CWideString = ""
For nIndex = 1 To LenB(bsString)
CWideString = CWideString & Chr(AscB(MidB(bsString, nIndex, 1)))
Next
End Function

HTTP Based Multipart Web Form File Upload
Anybody knows anything about it?

If so, can you show me some sample code?

VB Upload File Chinese OS - HTTP Post Body Method- HELP !
Hi Guys,

Me trying to upload file using VB HTTP Post method. Can successfully upload the files when my client machine is English OS . However , the problem occurs when am trying to upload the files from Chinese OS. It seems that the file uploaded is getting corrupted and could not be opened in correct format. This is applicable for binary files. The text files could be uploaded successfully.
I have tried setting content-type, charset,codepage etc properties to assemble the body.

Can anyone help me ? Its urgent ....Hope to find some VB GURU in this group.HELP !

Thanks in advance,
Ashish.0.


Part of the code :

--------------------------------------------

Sub uploadFile(a_strUserName As String, a_strUserPassword As String, a_strDigiteServerURL As String, a_strFilename As String, a_strFileTitle)

On Error GoTo err_uploadFile

Const HTTPREQUEST_PROXYSETTING_DEFAULT = 0
Const HTTPREQUEST_PROXYSETTING_PRECONFIG = 0
Const HTTPREQUEST_PROXYSETTING_DIRECT = 1
Const HTTPREQUEST_PROXYSETTING_PROXY = 2

Const HTTPREQUEST_SETCREDENTIALS_FOR_SERVER = 0
Const HTTPREQUEST_SETCREDENTIALS_FOR_PROXY = 1

' WinHTTPRequest options
Const WinHttpRequestOption_UserAgentString = 0
Const WinHttpRequestOption_URL = 1
Const WinHttpRequestOption_URLCodePage = 2
Const WinHttpRequestOption_EscapePercentInURL = 3
Const WinHttpRequestOption_SslErrorIgnoreFlags = 4
Const WinHttpRequestOption_SelectCertificate = 5
Const WinHttpRequestOption_EnableRedirects = 6
Const WinHttpRequestOption_UrlEscapeDisable = 7
Const WinHttpRequestOption_UrlEscapeDisableQuery = 8
Const WinHttpRequestOption_SecureProtocols = 9
Const WinHttpRequestOption_EnableTracing = 10

Const SslErrorFlag_Ignore_All = 13056

Const HTTP_STATUS_PROXY_AUTH_REQ = 407
Const HTTP_STATUS_DENIED = 401
Const HTTP_STATUS_OK = 200

Dim strFile As String
Dim strURL As String
Dim strBody As String
Dim aPostBody() As Byte
Dim nFile As Integer

' Read the file from the hard disk
nFile = FreeFile
Open a_strFilename For Binary As #nFile
strFile = String(LOF(nFile), " ")
Get #nFile, , strFile
Close #nFile

''' Dim w_objWinHttpRequest As New WinHttp.WinHttpRequest
Dim w_strRequestURL As String
Dim w_strProxyURL As String

''' Set g_objWinHttpRequest = CreateObject("WinHttp.WinHttpRequest.5.1")

w_strProxyURL = getProxyURL()

If Len(w_strProxyURL) > 0 Then
g_objWinHttpRequest.SetProxy HTTPREQUEST_PROXYSETTING_PROXY, w_strProxyURL, getProxyByPassServerList()

End If

w_strRequestURL = a_strDigiteServerURL & JSP_FILE_UPLOAD

g_objWinHttpRequest.SetTimeouts 0, 0, 0, 0

g_objWinHttpRequest.Open "POST", w_strRequestURL, False

' Set the header < here i have tried setting the charset , codepage parameters too but of little use as on the server 'side the extraction of the zip file is not done according to the given encoding method.>
g_objWinHttpRequest.SetRequestHeader "Content-Type", "multipart/form-data; boundary=Xu02=$"

' Assemble the body
strBody = "--Xu02=$" & vbCrLf & _
"Content-Disposition: form-data; name=""TestFile""; filename=""" & a_strFileTitle & """" & vbCrLf & _
"Content-type: file" & vbCrLf & vbCrLf & _
strFile & vbCrLf & _
"--Xu02=$--"

' Because of binary zeros, post body has to convert to byte array
aPostBody = StrConv(strBody, vbFromUnicode, g_lngLocaleID) 'vbFromUnicode

WriteToLogFile ("strbody :" & strBody & " localeid: " & g_lngLocaleID)

g_objWinHttpRequest.Option(WinHttpRequestOption_EnableHttpsToHttpRedirects) = True

g_objWinHttpRequest.Option(WinHttpRequestOption_SelectCertificate) = True

g_objWinHttpRequest.Option(WinHttpRequestOption_SslErrorIgnoreFlags) = SslErrorFlag_Ignore_All

g_objWinHttpRequest.SetClientCertificate "LOCAL_MACHINEOther People"
g_objWinHttpRequest.Send aPostBody 'posts the body to JSP.

If g_objWinHttpRequest.Status = HTTP_STATUS_DENIED Then
g_objWinHttpRequest.SetCredentials a_strUserName, a_strUserPassword, HTTPREQUEST_SETCREDENTIALS_FOR_SERVER
g_objWinHttpRequest.Send aPostBody

End If

Exit Sub

err_uploadFile:

m_ErrorDesc = "err_uploadFile [ERROR] : " & err.Description
m_ErrorFlag = True
WriteToLogFile "err_uploadFile [ERROR] : " & err.Description

End Sub


---------------------------------------------

Upload With WinInet
    I wrote application for uploading large files using WinInet HttpSendRequestEx. It seems to work OK, but after the HttpOpenRequest call the value of Err.LastDLLError is 122 (ERROR_INSUFFICIENT_BUFFER as in winerror.h mentioned; "The data area passed to a system call is too small"). Moreover, then I'm trying to make call to HttpEndRequest it returns false (i guess it's no good).
    The most interesting is that uploading actually works but my callback function does not receive INTERNET_STATUS_REQUEST_COMPLETE or INTERNET_STATUS_RESPONSE_RECEIVED (note, that it receives INTERNET_STATUS_SENDING_REQUEST INTERNET_STATUS_REQUEST_SENT). Unfortunately my application should know then all uploaded files have been recieved by server, so I really need to catch INTERNET_STATUS_RESPONSE_RECEIVED.

Upload With WinInet
Hi!

I have developed an application for uploading large files: Windows XP SP2/ MS VB 6.0 SP5/ IE 5.1/WinInet DLL.
And it works: files are uploaded on server. :-)

But I have one problem: the application(client-side) must know when server has completed processing the uploaded files.
I know 2 ways to achieve it.

1. Use InternetSetStatusCallback
I have implemented this way and my CallbackStatus function receives some statuses (for example INTERNET_STATUS_SENDING_REQUEST and INTERNET_STATUS_REQUEST_SENT
), but not all statuses!! The function does not receive INTERNET_STATUS_REQUEST_COMPLETE, INTERNET_STATUS_RECEIVING_RESPONSE and INTERNET_STATUS_RESPONSE_RECEIVED statuses (I suppose these statuses means the server has completed processing the request).

2. Use HttpQueryInfo and InternetReadFile after HttpEndRequest.
I also have issue in this case:
when I call HttpQueryInfo or InternetReadFile then I receive next error: "The requested operation can not be carried out because the handle supplied is not in the correct state". As result, I can not receive query info or server response. :-(

Could somebody help me? Any ideas!

PS
I think it is important (but not sure):
At once after the call HttpOpenRequest the value of Err.LastDLLError is 122 (ERROR_INSUFFICIENT_BUFFER as in winerror.h mentioned; "The data area passed to a system call is too small"). I'm really confused: What buffer means?
Moreover, when I'm trying to call HttpEndRequest it returns False (and Err.LastDLLError is 87. I guess it's not good).
The most interesting is that the application works!!

Upload Files From VB With WININET
Good day to all. I have a problem using WinInet to upload a file to a web server. I get error 87 when I try to execute HTTPsendRequesstEX. I'm using sendRequestEX as I need Async communications.

I have a valid internet File Handle and there are no permissions issues on the server (IIS is installed on my laptop).

Here is the code snippet:

**** START OF SNIPPET ****
hRequest = HttpOpenRequest(hConnect, "PUT", "/filer/test.txt", vbNullString, vbNullString, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0)
Rem *** All GOOD to here. at this point I have a valid connection to the server.

' This is the way it Must be called.
'BOOL HttpSendRequestEx(
' HINTERNET hRequest, Handle returned by HttpOpenRequest.
' LPINTERNET_BUFFERS lpBuffersIn, Optional. Pointer to an INTERNET_BUFFERS structure
' LPINTERNET_BUFFERS lpBuffersOut, Optional. Pointer to an INTERNET_BUFFERS structure
' DWORD dwFlags, reserved and MUST be set to zero
' DWORD dwContext Application-defined context value
');

Status = HttpSendRequestEx(hRequest, IB, vbNull, 0, 0) ' THISS CAUSES THE ERROR
If Status = 0 Then ' HERE IS WHERE I CATCH THE ERROR
MsgBox ("HttpSendRequestEx Err: " & Err.LastDllError)
Unload Me
End
End If

**** END OF SNIPPET ****

I have already developed FILE DOWNLOAD code (which is extremely fass -> 80 mb in about 2 minutes). I need to have an UPLOAD FILE piece for a project that I am working on in house.

Any help would be greatly appreciated.

Thanks

Goomba
ps: please feel free to email me directly at: rgutery@mentorits.com

Upload Response Using WININET
I am trying to download an HTTP file using the WININET.ocx / ddl. Unfortunately I have to pass through a survey questionnaire to get to the data that I am looking for. If I just download the URL I download the survey questionnaire and not the data. Is there any way to pass up information that would meet the survey’s requirement and then signal a ‘send’ command, then download the data?

Is Wininet.dll API Can Be Used With VB 6 To Upload Files Using SFTP?
Currently my application is written in VB using wininet.dll API to FTP files. New requirement is to use SFTP instead of FTP in VB only. Is wininet.dll API supports sftp?

Thanks in advance
Lokesh

Upload Files From VB With WININET - Error Please Help.
Good day to all. I have a problem using WinInet to upload a file to a web server. I get error 87 when I try to execute HTTPsendRequesstEX. I'm using sendRequestEX as I need Async communications.

I have a valid internet File Handle and there are no permissions issues on the server (IIS is installed on my laptop).

Here is the code snippet:

**** START OF SNIPPET ****
hRequest = HttpOpenRequest(hConnect, "PUT", "/filer/test.txt", vbNullString, vbNullString, 0, INTERNET_FLAG_NO_CACHE_WRITE, 0)
Rem *** All GOOD to here. at this point I have a valid connection to the server.

' This is the way it Must be called.
'BOOL HttpSendRequestEx(
' HINTERNET hRequest, Handle returned by HttpOpenRequest.
' LPINTERNET_BUFFERS lpBuffersIn, Optional. Pointer to an INTERNET_BUFFERS structure
' LPINTERNET_BUFFERS lpBuffersOut, Optional. Pointer to an INTERNET_BUFFERS structure
' DWORD dwFlags, reserved and MUST be set to zero
' DWORD dwContext Application-defined context value
');

Status = HttpSendRequestEx(hRequest, IB, vbNull, 0, 0) ' THISS CAUSES THE ERROR
If Status = 0 Then ' HERE IS WHERE I CATCH THE ERROR
MsgBox ("HttpSendRequestEx Err: " & Err.LastDllError)
Unload Me
End
End If

**** END OF SNIPPET ****

I have already developed FILE DOWNLOAD code (which is extremely fass -> 80 mb in about 2 minutes). I need to have an UPLOAD FILE piece for a project that I am working on in house.

Any help would be greatly appreciated.

Thanks

Goomba
ps: please feel free to email me directly at: rgutery@mentorits.com

HTTP Vs HTTPS Using WinInet.dll
I have set up my VB app to POST some information for me, which is working over HTTP. I am told there are several changes I must make to get the code to work with SSL, however after making those changes, it doesn't work.

Here is a code fragment that demonstrates the changes I have made. I have also been told that when specifing a secure site, you need to use https://www.XXX.com as opposed to www.XXX.com (with no http) for the value of Server in the following code. I have already done that. Notice these changes, depending on whether Secure is set or not.

InternetOpen - no change
InternetConnect - changed from INTERNET_INVALID_PORT_NUMBER to INTERNET_DEFAULT_HTTPS_PORT (also server has https:// in front of it)
HttpOpenRequest - Added INTERNET_FLAG_SECURE flag
HttpSendRequest - no change

Currently, I get an error from HttpSendRequest when operating in secure mode. It returns a Boolean error, and GetLastError returns 0, so there is no useful error message I can get.


Code:
hOpen = InternetOpen("WGHelper.exe", _
INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0)
If hOpen <> 0 Then
If Secure Then
hConnection = InternetConnect(hOpen, Server, INTERNET_DEFAULT_HTTPS_PORT, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
Else
hConnection = InternetConnect(hOpen, Server, INTERNET_INVALID_PORT_NUMBER, _
"", "", INTERNET_SERVICE_HTTP, 0, 0)
End If
If hConnection <> 0 Then
If Secure Then
hURL = HttpOpenRequest(hConnection, "POST", CGI, "", "", 0, _
INTERNET_FLAG_KEEP_CONNECTION Or INTERNET_FLAG_SECURE, 0)
Else
hURL = HttpOpenRequest(hConnection, "POST", CGI, "", "", 0, _
INTERNET_FLAG_KEEP_CONNECTION, 0)
End If
If hURL <> 0 Then
If HttpSendRequest(hURL, "", 0, _
postBuffer, Len(postBuffer)) Then

Wininet API HTTP Query
Hi all,

I'm having big troubles getting the wininet api to return specific http queries.
On this MSDN page, I found a nice query that I would like to pass to a server:
http://msdn.microsoft.com/library/de...info_flags.asp

HTTP_QUERY_CONTENT_BASE
50

But I can't seem to get it working...
I read this page (http://msdn.microsoft.com/library/de...sdn_vbhttp.asp) a thousand times, and tried and tried, but with no success.

Then, I found some code and modded it for the following query:
See: attachment!

HTTP_QUERY_RAW_HEADERS_CRLF
22

This seems to work just fine, but the above query (HTTP_QUERY_CONTENT_BASE ) keeps returning an empty result!

I was wondering if someone can help me getting the above query working.

Thanks a lot for your help!

JeffreyEdit by herilane: Please do not post executable files.

HTTP Vs HTTPS Using WinInet.dll
I have set up my VB app to POST some information for me, which is working over HTTP. I am told there are several changes I must make to get the code to work with SSL, however after making those changes, it doesn't work.

Here is a code fragment that demonstrates the changes I have made. I have also been told that when specifing a secure site, you need to use https://www.XXX.com as opposed to www.XXX.com (with no http) for the value of Server in the following code. I have already done that. Notice these changes, depending on whether Secure is set or not.

InternetOpen - no change
InternetConnect - changed from INTERNET_INVALID_PORT_NUMBER to INTERNET_DEFAULT_HTTPS_PORT (also server has https:// in front of it)
HttpOpenRequest - Added INTERNET_FLAG_SECURE flag
HttpSendRequest - no change

Currently, I get an error from HttpSendRequest when operating in secure mode. It returns a Boolean error, and GetLastError returns 0, so there is no useful error message I can get.


VB Code:
hOpen = InternetOpen("WGHelper.exe", _      INTERNET_OPEN_TYPE_PRECONFIG, "", "", 0)   If hOpen <> 0 Then      If Secure Then        hConnection = InternetConnect(hOpen, Server, INTERNET_DEFAULT_HTTPS_PORT, _          "", "", INTERNET_SERVICE_HTTP, 0, 0)      Else        hConnection = InternetConnect(hOpen, Server, INTERNET_INVALID_PORT_NUMBER, _          "", "", INTERNET_SERVICE_HTTP, 0, 0)      End If      If hConnection <> 0 Then        If Secure Then          hURL = HttpOpenRequest(hConnection, "POST", CGI, "", "", 0, _            INTERNET_FLAG_KEEP_CONNECTION Or INTERNET_FLAG_SECURE, 0)        Else         hURL = HttpOpenRequest(hConnection, "POST", CGI, "", "", 0, _            INTERNET_FLAG_KEEP_CONNECTION, 0)        End If         If hURL <> 0 Then            If HttpSendRequest(hURL, "", 0, _               postBuffer, Len(postBuffer)) Then

HTTP Post Using WININET
Guys,
I neeed your help here in solving my problem. My problem is i was able to do a http post an XML message to a website without username and password. Now I want to do a http post to a website using username and password. For my previous applications I didn't need authentication but now for my new application I need to supply username and password while doing HTTP POST. How do i do that? Please let me know. I appreciate any kind of input on this.

Thanks in advance,
DilSe..

Http Wininet Calls
Help
We are attempting to create an ActiveX control that will take a userid and password (that are provided in base64) and authenticate to the server without the login screen popping up. We have found some documentation to open, connect, and openrequest and using the set option to set the userid and password, but are haveing trouble getting the headers set up correctly. We suspect that we may need the handle for the header, but don't know how to get it.
Any sample code or suggestions would be greatly appreciated.

Frustrated in Minnesota

HTTP Downloading With WinInet
Hi all,

I have this code to download a file from HTTP and its working fine. Can anyone modify this code with InternetSetFilePointer to show download progress in a progressbar.

Thanks

Code:
Option Explicit
Const scUserAgent = "test program"
Const INTERNET_OPEN_TYPE_DIRECT = 1
Const INTERNET_OPEN_TYPE_PROXY = 3
Const INTERNET_FLAG_RELOAD = &H80000000
'Const sURL = "http://www.microsoft.com/index.htm"
Const sURL = "http://www.geocities.com/usamaalam/abstract.doc"
Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Private Declare Function InternetCloseHandle Lib "wininet" (ByRef hInet As Long) As Long
Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Private Declare Function InternetOpenUrl Lib "wininet" Alias "InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String, ByVal lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As Long, ByVal dwContext As Long) As Long

Private Sub Command1_Click()
Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long
'Create a buffer for the file we're going to download
sBuffer = Space(30720)
'Create an internet connection
hOpen = InternetOpen(scUserAgent, INTERNET_OPEN_TYPE_DIRECT, vbNullString, vbNullString, 0)

'Open the url
hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&, INTERNET_FLAG_RELOAD, ByVal 0&)
'Read the first 1000 bytes of the file
InternetReadFile hFile, sBuffer, 30720, Ret
'clean up
InternetCloseHandle hFile
InternetCloseHandle hOpen
'Show our file
MsgBox sBuffer

Open "C:Documents and SettingsAdministratorDesktopabc.doc" For Binary Access Write As #1
Put #1, , sBuffer
DoEvents
Close #1

End Sub

Asynchronous Wininet HTTP
Im totally stressing over this, im trying to asynchronously retrieve files. C++ Disassembler returns this error for the illegal operation the following code generates.

Quote:*** Wininet Assertion failed: dwStatus != INTERNET_STATUS_REQUEST_COMPLETE
*** Source file: e:
1inetcorewininetdll hrdinfo.cxx
*** Source line: 1514
*** Thread fffdb5e1
Code:Dim hOpen As Long, hOpenUrl As Long

    hOpen = InternetOpen(App.Title, INTERNET_OPEN_TYPE_PRECONFIG, vbNullString, vbNullString, INTERNET_FLAG_ASYNC)
    Call InternetSetStatusCallback(hOpen, AddressOf StatusCallback)
    hOpenUrl = InternetOpenUrl(hOpen, "http://www.google.com/index.html", vbNullString, 0, &H80000000, 0)
    Call InternetCloseHandle(hOpenUrl)
    Call InternetCloseHandle(hOpen)

Declarations
Code:Public Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" (ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
Public Declare Function InternetOpenUrl Lib "wininet.dll" Alias "InternetOpenUrlA" (ByVal hOpen As Long, ByVal sUrl As String, ByVal sHeaders As String, ByVal lLength As Long, ByVal lFlags As Long, ByVal lContext As Long) As Long
Public Declare Function InternetReadFile Lib "wininet.dll" (ByVal hFile As Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long, lNumberOfBytesRead As Long) As Integer
Public Declare Function InternetCloseHandle Lib "wininet.dll" (ByVal hInet As Long) As Integer
Public Declare Sub InternetSetStatusCallback Lib "wininet.dll" (ByVal pub_lngInternetSession As Long, ByVal lpfnInternetCallback As Long)

Public Const INTERNET_STATUS_RESOLVING_NAME = 10
Public Const INTERNET_STATUS_NAME_RESOLVED = 11
Public Const INTERNET_STATUS_CONNECTING_TO_SERVER = 20
Public Const INTERNET_STATUS_CONNECTED_TO_SERVER = 21
Public Const INTERNET_STATUS_SENDING_REQUEST = 30
Public Const INTERNET_STATUS_REQUEST_SENT = 31
Public Const INTERNET_STATUS_RECEIVING_RESPONSE = 40
Public Const INTERNET_STATUS_RESPONSE_RECEIVED = 41
Public Const INTERNET_STATUS_CTL_RESPONSE_RECEIVED = 42
Public Const INTERNET_STATUS_PREFETCH = 43
Public Const INTERNET_STATUS_CLOSING_CONNECTION = 50
Public Const INTERNET_STATUS_CONNECTION_CLOSED = 51
Public Const INTERNET_STATUS_HANDLE_CREATED = 60
Public Const INTERNET_STATUS_HANDLE_CLOSING = 70
Public Const INTERNET_STATUS_REQUEST_COMPLETE = 100

Public Const INTERNET_OPEN_TYPE_PRECONFIG = 0
Public Const INTERNET_FLAG_ASYNC = &H10000000

Public Sub StatusCallback(ByVal hInternet As Long, ByVal dwContext As Long, ByVal dwStatus As Long, ByVal pbStatusInformation As Long, ByVal dwStatusInformationLength As Long)
    
    Select Case dwStatus
        Case INTERNET_STATUS_RESOLVING_NAME
        Case INTERNET_STATUS_NAME_RESOLVED
        Case INTERNET_STATUS_CONNECTING_TO_SERVER
        Case INTERNET_STATUS_CONNECTED_TO_SERVER
        Case INTERNET_STATUS_SENDING_REQUEST
        Case INTERNET_STATUS_REQUEST_SENT
        Case INTERNET_STATUS_RECEIVING_RESPONSE
        Case INTERNET_STATUS_RESPONSE_RECEIVED
        Case INTERNET_STATUS_CLOSING_CONNECTION
        Case INTERNET_STATUS_CONNECTION_CLOSED
        Case INTERNET_STATUS_HANDLE_CREATED
        Case INTERNET_STATUS_HANDLE_CLOSING
        Case INTERNET_STATUS_REQUEST_COMPLETE
    End Select
    
End Sub

There doesnt seem to be much info on wininet api in vb



Edited by - Daniel on 8/9/2003 2:29:20 AM

Upload Through HTTP
How would I be able to upload text from my textbox on my form to my webserver's text file. Someone gave me code before to download, but I'm confused about uploading. Please Help

Private Sub Socket_Connect()

HTTPrequest = "GET /OutDate.txt HTTP/1.1"
HTTPrequest = HTTPrequest & vbCrLf & "Host: www.lxl-antiban.com" 'and this line
HTTPrequest = HTTPrequest & vbCrLf & "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, application/vnd.ms-powerpoint, */*"
HTTPrequest = HTTPrequest & vbCrLf & "Accept -Language: en -us"
HTTPrequest = HTTPrequest & vbCrLf & "Accept -Encoding: gzip , deflate"
HTTPrequest = HTTPrequest & vbCrLf & "User-Agent: Mozilla/4.0 (compatible; MSIE 4.01; Windows 95)"
HTTPrequest = HTTPrequest & vbCrLf & "Connection: Keep -Alive" & vbCrLf & vbCrLf
Socket.SendData HTTPrequest

End Sub

Private Sub Socket_DataArrival(ByVal bytesTotal As Long)
Socket.GetData dat$
'----------
txtOutDate = dat$
Socket.Close
End Sub

HTTP Upload
Hi,

How can I upload a file to a HTTP server? (I know the required username and password). I know this can be done as web sites can do this, e.g. on forums you can upload your own avatar etc.

Thanks

HTTP Upload With Inet
Hello everybody,

i have a little problem, i have to upload files with http and at the moment i have no idea how to manage it. Could somebody help me?

Yours Stinkbaer

JPG Upload Using HTTP Protocal With VB
Please help me how can I upload a file using HTTP Protocal ?

Http Upload From Within Excel (vba)
Hi,

I need to upload a zip file to a http-server. A html formupload (<input type="file">) works fine and neat. But my excel code fails to send a proper post method. So I wasted so much time finding out the proper headers (msdn and rfc) and methods that I'm willing to simply copy code that anyone could/would provide.

Did anyone succed in this?
thanks for any hint or code.

HTTP Upload Issues, Please Help.
I am trying to upload files to a CGI application. This has been tested using the XUpload component (http://aspupload.com) so I know that the backend works. I have the header information and form data implemented correctly, but my issue is getting the binary file data into the post message. I would like to put it into a simple String, but here is what I get using the following code for the file 0004.JPG

Code:
Private Sub Command1_Click()
    Dim oHTTP As New XMLHTTP30
    Dim sFormData As String
    Dim sFileBody As String
    Dim ac As Integer
    
    Dim sFileLocation As String
    
    sFileLocation = "C:004.jpg"
    
   Dim s As String, bDummy As Byte
    Open sFileLocation For Binary As #1
    
    s = Space$(LOF(1))
    
    For ac = 1 To LOF(1)
        Get #1, ac, bDummy
          
    s = s & CStr(bDummy)
    
    
    Next ac
    Close #1
    
    sFormData = "-----------------------------7d323f12e0740" & vbCrLf & "Content-Disposition: form-data; name=" & """" & "file" & """" & "; filename=" & """" & _
    "C:004.jpg" & """" & vbCrLf & "Content-Type: image/pjpeg" & vbCrLf & vbCrLf & _
    s & vbCrLf & "-----------------------------7d323f12e0740" & vbCrLf & "Content-Disposition: form-data; name=" & """" & "comments" & """" & vbCrLf & vbCrLf & vbCrLf & _
    "-----------------------------7d323f12e0740" & vbCrLf & "Content-Disposition: form-data; name=" & """" & "uploader" & """" & vbCrLf & vbCrLf & vbCrLf & _
    "-----------------------------7d323f12e0740--"
    
    MsgBox sFormData

    oHTTP.open "POST", "http://192.168.0.2/cgi-bin/cgi4upld2.exe", False
    oHTTP.setRequestHeader "Content-Type", "multipart/form-data"
    oHTTP.send sFormData
    
    MsgBox oHTTP.responseText
    
End Sub


The uploaded file contains this
"30910222324252637383940414" and so on

when it should contain this

ÿØÿà JFIF  ,, ÿþ LEAD Technologies Inc. V1.01 ÿÛ „          
.

What is the problem with my code? What is the best way to do this?

Problem In UPload Through HTTP
Hello
As I already poast for the same problem of uploading in fTP. Here i have again a Problem in Uploading. but this time problem in HttP. When i was using FTP to Upload File, On some Clients PC it gives a Windows FireWall error.
So I use Http and Start upload File. But Still SOe Client have a same Firewall Problem during Upload.

This Time I am Usng Http. Is Firewall Block Http??? Or any Other Reason is there. I try the Application on many pc by making the Firewall on and not allowing the Exception. but they works fine on my Pc. But can Work on Clients PC.

HTTP Upload - An Answer
I have seen a number of posts requesting how to upload a file programmatically via HTTP. Here is a solution in VB using the INet control.


Dim oFileSystem as new Scripting.FileSystemObject

s = "-----------------------------AaB03x" & vbCrLf & _
"content-disposition: form-data; name=""field1""; filename=""autoexec.bat""" & vbCrLf & _
"Content-Type: text/plain" & vbCrLf & vbCrLf & _
oFileSystem.GetFile("c:autoexec.bat").OpenAsTextStream.ReadAll & _
"-----------------------------AaB03x--"
Inet1.Execute "http://localhost/sample1.asp", _
"POST", s, "Content-type: multipart/form-data, boundary=AaB03x"




Synopsis... A Request is formatted according to RFC1867 using the FileSystem object to insert the file content. It then posts it to the URL using the INet routines.

I can send more information upon request and please send me any feedback on this.

&gt;Winsock Http Upload From Client&lt;
How can i upload a mp3 file with winsock from a client to a server. The client doesn't have a webserver.. Is this possible, so yes: please past a code here...

Thnx

How To U Upload And Download .TXT &amp; .MDB Files Using HTTP Protocol In Vb With Using A
Respected All,

i want to upload and download .TXT & .MDB files using vb through code with HTTP Protocol
using internet transfer control or winsock control

how to rename the Remote files?
how to delete them ?
how to find out whether particular file exists on the Remote server or not ?
how to hide the file from the remote server?

waiting for ur reply

with warm regards
Amol Sangamnerkar

How ??? To Upload Binary Files To A Web Server Using HTTP Protocol ???
I tried to create a VB client application that need to upload files to a specific Web Browser using HTTP protocol. I used Internet Transfer Control to post data to Html page. It's work fine with plaint text files but I want that program to upload binary data.
Can help me anyone??

Unable To Upload To The VBCity HTTP Server !!. Resolved.
Gentlemen,
        For the last couple of days, I have been trying to upload a project to one of the members [ VBCity]. I’m getting an “ HTTP 500 - Internal server error. “ It look like the FTTP server piece on the server has to be recycled.


I hope this Helps !!

Good Luck,

Tom El Hindi < Microsoft VB MVP >

"When there is the will !!! There is the mind for it !."


Edited by - tom77757 on 7/7/2003 6:13:10 AM

WinInet - File Download
Hi,

I am trying to download a file from FTP and got this code from this site but I am unable to get the file. I am trying to donwload ftp.microsoft.com//Products/msmq/demos.zip .

Can anyone tell me what I am doing wrong or give me code for just download a file from FTP using WinInet API.


VB Code:
Private Declare Function InternetWriteFile Lib "wininet.dll" _(ByVal hFile As Long, ByRef sBuffer As Byte, ByVal lNumBytesToWite As Long, _dwNumberOfBytesWritten As Long) As Integer Private Declare Function FtpOpenFile Lib "wininet.dll" Alias "FtpOpenFileA" _(ByVal hFtpSession As Long, ByVal sBuff As String, ByVal Access As Long, ByVal Flags As Long, ByVal Context As Long) As Long Private Declare Function InternetOpen Lib "wininet.dll" Alias "InternetOpenA" _(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As String, _ByVal sProxyBypass As String, ByVal lFlags As Long) As Long Private Declare Function InternetConnect Lib "wininet.dll" Alias "InternetConnectA" _(ByVal hInternetSession As Long, ByVal sServerName As String, ByVal nServerPort As Integer, _ByVal sUsername As String, ByVal sPassword As String, ByVal lService As Long, _ByVal lFlags As Long, ByVal lContext As Long) As Long Private Declare Function InternetCloseHandle Lib "wininet.dll" _(ByVal hInet As Long) As Long Option Explicit Dim hOpen As Long, hConnection As Long, hFile As LongDim dwType As Long  Private Sub Connect()   If hConnection <> 0 Then        InternetCloseHandle hConnection    End If    hConnection = InternetConnect(hOpen, "ftp.microsoft.com/Products/msmq/", 0, _    "", "", 1, 0, 0)    If hConnection = 0 Then        'ErrorOut Err.LastDllError, "InternetConnect"        Exit Sub    Else        MsgBox "Connected!", , "SimpleFtp"            End IfEnd Sub Private Sub Command4_Click()'&H40000000 == GENERIC_WRITEDim Data(99) As Byte ' array of 100 elements 0 to 99Dim Written As LongDim Size As LongDim Sum As LongDim j As Long Sum = 0j = 0' for ASCII files use FTP_TRANSFER_TYPE_ASCIIhFile = FtpOpenFile(hConnection, "demos.zip", &H40000000, 2, 0)If hFile = 0 Then    'ErrorOut Err.LastDllError, "FtpOpenFile"    Exit SubEnd IfOpen "D:TestFile.zip" For Binary Access Read As #1Size = LOF(1)ProgressBar1.Max = SizeFor j = 1 To Size 100    Get #1, , Data    If (InternetWriteFile(hFile, Data(0), 100, Written) = 0) Then        'ErrorOut Err.LastDllError, "InternetWriteFile"        Exit Sub    End If    DoEvents    Sum = Sum + 100    Label7.Caption = Str(Sum)    ProgressBar1.Value = Sum    Next jGet #1, , Data If (InternetWriteFile(hFile, Data(0), Size Mod 100, Written) = 0) Then        'ErrorOut Err.LastDllError, "InternetWriteFile"        Exit SubEnd IfSum = Sum + (Size Mod 100)Label7.Caption = Str(Sum)ProgressBar1.Value = SumClose #1InternetCloseHandle (hFile)End SubPrivate Sub Command1_Click()ConnectCommand4_Click End Sub Private Sub Form_Load()  hOpen = InternetOpen("My VB Test", 0, vbNullString, vbNullString, 0)  If hOpen = 0 Then'    ErrorOut Err.LastDllError, "InternetOpen"    Unload Form1  End If ProgressBar1.Max = 100ProgressBar1.Value = 0End Sub


Thanks.

Uploading File Using WinInet
Hello!
How I can upload file by HTTP using wininet.dll? (VB6)
Example, please.

Set File Permissions Using WinInet FtpCommand
I'm trying to use the FtpCommand function in Microsoft's WinInet.dll library to set file and directory permissions on a UNIX FTP server.

When I run the following command from the MS DOS FTP client, it works and returns the following response:

ftp> quote site chmod 0700 mydir
250 Changed.

When I try to issue the same command via the FtpCommand function, it fails. Here is the response I get back from the FTP server:

200 Type okay.
200 PORT command successful.
500 Syntax error, command unrecognized.

I am running this command from the root directory.
The directory I am trying to change perms for is directly under the root directory.
I have tried specifying the directory using both "/mydir" AND "mydir".
Have also tried specifying the command string as "quote SITE CHMOD 700 mydir".

Any help greatly appreciated.

Copyright 2005-08 www.BigResource.com, All rights reserved