[GB.NET.CURL]
* NEW: Add a Gambas part to the component. * NEW: HttpForm is a new class that inherits HttpClient and that allows to post HTML forms easily. git-svn-id: svn://localhost/gambas/trunk@6567 867c0c6c-44f3-4631-809d-bfa615b0a4ec
This commit is contained in:
parent
04fc7adb58
commit
c9f03a1150
2
gb.net.curl/src/gb.net.curl/.directory
Normal file
2
gb.net.curl/src/gb.net.curl/.directory
Normal file
@ -0,0 +1,2 @@
|
||||
[Desktop Entry]
|
||||
Icon=./.icon.png
|
13
gb.net.curl/src/gb.net.curl/.gitignore
vendored
Normal file
13
gb.net.curl/src/gb.net.curl/.gitignore
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
#---- Gambas files to ignore (v1)
|
||||
*.gambas
|
||||
.lock
|
||||
*~
|
||||
core
|
||||
core.*
|
||||
vgcore
|
||||
vgcore.*
|
||||
.kdbg*
|
||||
.*.prof
|
||||
.lang/*.pot
|
||||
.gambas/*
|
||||
#----
|
BIN
gb.net.curl/src/gb.net.curl/.icon.png
Normal file
BIN
gb.net.curl/src/gb.net.curl/.icon.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.9 KiB |
31
gb.net.curl/src/gb.net.curl/.info
Normal file
31
gb.net.curl/src/gb.net.curl/.info
Normal file
@ -0,0 +1,31 @@
|
||||
#HttpForm
|
||||
HttpClient
|
||||
C
|
||||
Add
|
||||
m
|
||||
|
||||
(Field)s(Value)s
|
||||
AddFile
|
||||
m
|
||||
|
||||
(Field)s(Path)s[(Name)s]
|
||||
Remove
|
||||
m
|
||||
|
||||
(Field)s
|
||||
_get
|
||||
m
|
||||
s
|
||||
(Field)s
|
||||
_put
|
||||
m
|
||||
|
||||
(Value)s(Field)s
|
||||
Clear
|
||||
m
|
||||
|
||||
|
||||
Submit
|
||||
m
|
||||
|
||||
|
1
gb.net.curl/src/gb.net.curl/.list
Normal file
1
gb.net.curl/src/gb.net.curl/.list
Normal file
@ -0,0 +1 @@
|
||||
HttpForm
|
10
gb.net.curl/src/gb.net.curl/.project
Normal file
10
gb.net.curl/src/gb.net.curl/.project
Normal file
@ -0,0 +1,10 @@
|
||||
# Gambas Project File 3.0
|
||||
# Compiled with Gambas 3.6.90
|
||||
Title=gb.net.curl
|
||||
Startup=MMain
|
||||
Version=3.6.90
|
||||
VersionFile=1
|
||||
Component=gb.net
|
||||
Component=gb.net.curl
|
||||
TabSize=2
|
||||
Packager=1
|
121
gb.net.curl/src/gb.net.curl/.src/HttpForm.class
Normal file
121
gb.net.curl/src/gb.net.curl/.src/HttpForm.class
Normal file
@ -0,0 +1,121 @@
|
||||
' Gambas class file
|
||||
|
||||
Export
|
||||
|
||||
Inherits HttpClient
|
||||
|
||||
Private $cVal As New Collection
|
||||
Private $aField As New String[]
|
||||
Private $cFile As New Collection
|
||||
|
||||
Public Sub Add(Field As String, Value As String)
|
||||
|
||||
If Not $aField.Exist(Field) Then $aField.Add(Field)
|
||||
$cVal[Field] = Value
|
||||
|
||||
End
|
||||
|
||||
Public Sub AddFile(Field As String, Path As String, Optional Name As String)
|
||||
|
||||
If Left(Path) <> "/" Then Path = ".." &/ Path
|
||||
If Not Exist(Path) Then Error.Raise("File does not exists")
|
||||
|
||||
If Not Name Then Name = File.Name(Path)
|
||||
Add(Field, Name)
|
||||
$cFile[Field] = Path
|
||||
|
||||
End
|
||||
|
||||
Public Sub Remove(Field As String)
|
||||
|
||||
Dim iPos As Integer
|
||||
|
||||
iPos = $aField.Find(Field)
|
||||
If iPos < 0 Then Return
|
||||
|
||||
$aField.Remove(iPos)
|
||||
$cVal.Remove(Field)
|
||||
$cFile.Remove(Field)
|
||||
|
||||
End
|
||||
|
||||
Public Sub _get(Field As String) As String
|
||||
|
||||
Return $cVal[Field]
|
||||
|
||||
End
|
||||
|
||||
Public Sub _put(Value As String, Field As String)
|
||||
|
||||
Add(Field, Value)
|
||||
|
||||
End
|
||||
|
||||
Public Sub Clear()
|
||||
|
||||
$cVal.Clear
|
||||
$aField.Clear
|
||||
|
||||
End
|
||||
|
||||
|
||||
Public Sub Submit()
|
||||
|
||||
Dim sBoundary As String
|
||||
Dim sPath As Variant
|
||||
Dim I As Integer
|
||||
Dim sPost As String
|
||||
Dim hPost As File
|
||||
Dim sField As String
|
||||
|
||||
Do
|
||||
|
||||
sBoundary = "------"
|
||||
For I = 1 To 4
|
||||
sBoundary &= Hex$(Int(Rnd(65536)), 4)
|
||||
Next
|
||||
|
||||
For Each sPath In $cFile
|
||||
If InStr(File.Load(sPath), sBoundary) Then Continue
|
||||
Next
|
||||
|
||||
Break
|
||||
|
||||
Loop
|
||||
|
||||
sPost = Temp$()
|
||||
|
||||
hPost = Open sPost For Create
|
||||
hPost.EndOfLine = gb.Windows
|
||||
|
||||
For Each sField In $aField
|
||||
|
||||
Print #hPost, "--"; sBoundary
|
||||
|
||||
sPath = $cFile[sField]
|
||||
|
||||
If sPath Then
|
||||
|
||||
Print #hPost, "Content-Disposition: form-data; name=\""; sField; "\"; filename=\""; $cVal[sField]; "\""
|
||||
Print #hPost, "Content-Type: application/octet-stream"
|
||||
Print #hPost
|
||||
Print #hPost, File.Load(sPath)
|
||||
|
||||
Else
|
||||
|
||||
Print #hPost, "Content-Disposition: form-data; name=\""; sField; "\""
|
||||
Print #hPost, "Content-Type: text/plain; charset=\"utf-8\""
|
||||
Print #hPost
|
||||
Print #hPost, $cVal[sField]
|
||||
|
||||
Endif
|
||||
|
||||
Next
|
||||
|
||||
Print #hPost, "--"; sBoundary; "--"
|
||||
|
||||
hPost.Close
|
||||
|
||||
Me.PostFile("multipart/form-data; boundary=" & sBoundary, sPost, ["Content-Length: " & CStr(Stat(sPost).Size)])
|
||||
|
||||
End
|
5
gb.net.curl/src/gb.net.curl/.src/MMain.module
Normal file
5
gb.net.curl/src/gb.net.curl/.src/MMain.module
Normal file
@ -0,0 +1,5 @@
|
||||
' Gambas module file
|
||||
|
||||
Public Sub Main()
|
||||
|
||||
End
|
9
gb.net.curl/src/gb.net.curl/.startup
Normal file
9
gb.net.curl/src/gb.net.curl/.startup
Normal file
@ -0,0 +1,9 @@
|
||||
MMain
|
||||
gb.net.curl
|
||||
0
|
||||
0
|
||||
3.6.90
|
||||
|
||||
gb.net
|
||||
gb.net.curl
|
||||
|
Loading…
x
Reference in New Issue
Block a user