GS_HTTP/Peacekeeper-plugin

Posted By: broozar

GS_HTTP/Peacekeeper-plugin - 11/04/06 23:11

hi all,

did anyone try this plugin? http://www.peacekeeper.com/3dgs/http.html
it works pretty well, but i can't get the upload done. i use

Code:
dll_handle = dll_open("GSHTTP.dll");
HTTP_Create(1);
waitt(16);
HTTP_PostFile(1,"http://www.hereComesTheUrl",the_file, ???);
waitt(16);
HTTP_Free(1);
dll_close(dll_handle);
wait(1);



where i've set the 3 ???, what do i have to fill in for "var_str"?

is there any other way to upload the file to a specific url?
Posted By: Gordon

Re: GS_HTTP/Peacekeeper-plugin - 11/05/06 05:20

in http_posfile you should have the directory of your exe as the first parameter and the file name of the LOCAL copy of the http file to send. there is no forth parameter as far as the documentation goes. the other thing is that it is for 5.5 not 6.4.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/05/06 10:02

can you give an exmple, please? i jsut don't get it, sorry.

furthermore, the documentation on the site says
dllfunction HTTP_PostFile(id,url_str,file_str); while the wdl that comes with the pac states
dllfunction HTTP_PostFile(id,url_str,file_str,var_str); whithout explaining var_str.

regarding the 5.5->6.4 problem, it works fine with 6.3.
Posted By: Gordon

Re: GS_HTTP/Peacekeeper-plugin - 11/05/06 14:02

ok I will dig into it today and see what I can find out.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/05/06 17:38

wonderful please post anything you can find out, even if it's not the solution, maybe it can help me already.
Posted By: Gordon

Re: GS_HTTP/Peacekeeper-plugin - 11/07/06 11:13

after digging through the source what I found was that you were correct in using a url for the first param. As for the third param.... use a different call http_postfile2. This should take care of your problems getting started.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/07/06 11:38

i had a go with postfile2, though i had no success. i guess it has something to do with the "directory of your acknex exe + fostfile". do i have to publish first, to get the exe and the file in one folder, before it will be uploaded? do i need an absolute or a relative path?
Posted By: Gordon

Re: GS_HTTP/Peacekeeper-plugin - 11/07/06 23:58

I think I will have to leave this last question for someone with more expreience with this plugin than I have.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/08/06 13:36

but you seem to be the only one who has. thanks a lot for your help, i will try to circumvenit the dll upload with a php script. let's see if i can do it. however, if you find anything else out about this feature, please keep me informed.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/08/06 20:31

ok, i have set up a form like this:

Code:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="file" name="datei" />
<input type="submit" value="Datei hochladen" />
</form>

<?php

if (isset($_FILES['datei']) and ! $_FILES['datei']['error'])
{

$filename = $_FILES['datei']['name'];
move_uploaded_file($_FILES['datei']['tmp_name'], $filename);

echo "<b>Status:</b> Upload komplett";

} else {

echo "<b>Status:</b> Fehler beim Upload";

}
?>



it's called upload.php. now i want to fill this form via the HTTP_Post command:

Code:
dll_handle = dll_open("GSHTTP.dll");
wait(1);
HTTP_Create(0);
wait(1);
while(HTTP_IsWorking(0)==1) {
waitt (16);
}
if (HTTP_Create(0)==0) {
HTTP_Post(0,"http://here's the URL/upload.php",poster2);}
HTTP_Free(0);
dll_close(dll_handle);



but no way, the file (path stored in poster2, no error there) simply doesn't get uploaded. what's wrong with it?
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/10/06 17:07

Code:

dll_handle = dll_open("GSHTTP.dll");
HTTP_Create(0);
HTTP_Post(0,"http://here's the URL/upload.php", poster2);
while (HTTP_IsWorking(0)) {
wait(1);
}
HTTP_Free(0);
dll_close(dll_handle);


Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/10/06 21:21

thanks, no error messages, but still no success. i bet it has something to do with the PHP part.
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/11/06 17:03

it's wrong, too...

Code:

<?php
// the php library can't know that you want your file attached to 'datei',
// since it does not parse the html code from above. so we need a plain php
// script that handles upload of anonymously uploaded files.
if (count($_FILES) && $_FILES[0]['error'])
{
$filename = $_FILES[0]['name'];
if (move_uploaded_file($_FILES[0]['tmp_name'], $filename)) {
echo "SUCCESS";
} else {
echo "FAILURE";
}
} else {
echo "FAILURE";
}
?>


Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/11/06 22:22

cool, but shouldn't it be ... && !$_FILES[0]['error'] ?

and how can i use it? just send the url to the script?
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/12/06 12:04

it should be, yes. just use it with the c-script code from above. well, i don't know how you want to use it, but i thought you'd like to upload a file... just use the file upload command of the plugin, and the url is this php script.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/12/06 12:07

hm, the fileUpload-command is HTTP_PostFile(2), your cscript code uses HTTP_Post (posting just the file path). please help me just once more... it'd be cool if it worked after all.
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/12/06 20:10

php script stays the same. use this c-script snippet to upload a file... afaik the file must be in the same directory as the exe file.

Code:

dll_handle = dll_open("GSHTTP.dll");
HTTP_Create(0);
HTTP_PostFile(0, "http://here's the URL/upload.php", "myfile.foo");
while (HTTP_IsWorking(0)) {
wait(1);
}
HTTP_Free(0);
dll_close(dll_handle);


Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/12/06 21:38

PostFile does not work ("crash in GSHTTP.dll") [as the documentation says, a 4th parameter, "var_str" is needed, but it's explained nowhere what it means and how to use it), postFile2 does not upload anything, but produces no errors. i am using exactly the code you do (except for the file names). still nothing.
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/14/06 18:26

well, i don't know the plugin, i'm coding blindly somehow. so if you want further help, give me the source code of the dll, or at least some kind of reference as where to look for further information. the php script does work, it's indeed the dll that has a problem.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/14/06 20:49

i just had an idea - "var_str" could be the var in the php script. which one is used for the upload? filename? _FILES?

ps: dll can be found here http://www.peacekeeper.com/3dgs/http.html (version 1.3, needs some c-script update as it's been done for a5)
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/15/06 16:31

no, $_FILES is a predefined dictionnary. well, if that's the case, use 'file' and change $_FILE[0] to $_FILE['file'] in the php script.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/15/06 23:58

tried, without success.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/16/06 00:05

this is the code that comes along with the dll in a *.pas file, i guess it's what you'd call the source code:

Quote:

function HTTP_PostFile(id: gsfixed; URL,Filename, pVar: PA4_STRING): gsfixed;
const
LR : String[2] = #13#10;
var
Buf,Boundry,ContentTypePost,PostVar: String;
FileToSend : TMemoryStream;
Error: Integer;
function Inputtext(Name,Value: String): string;
begin
result := format(lr+'%s%sContent-Disposition: form-data; name="%s"%s%s%s%s'+#13#10,[boundry,lr,name,lr,lr,lowercase( value ),lr] );
end;
begin
Error := 0;
try
PostVar := StrPas(pVar^.chars);
THTTPCli(HTTPList[FIX2INT(id)]).SendStream := TMemoryStream.Create;

Boundry := '-----------------------------7cf29e12c04'; { Specified in Multipart/form-data RFC }
ContentTypePost := 'multipart/form-data; boundary=' + copy(Boundry,3,length(boundry));

Buf := Boundry + LR + 'Content-Disposition: form-data; name="uploadFile1"; filename="' + ExtractFileName(ExtractFilePath(ParamStr(0)) + StrPas(filename^.chars)) + '"'
+ LR + 'Content-Type: application/x-compress' + LR + LR;
//i don't think the IMAGE/PJPEG matters much
//my opinion on this would be that once it's set as this
//the file will be uploaded in BINARY

THTTPCli(HTTPList[FIX2INT(id)]).SendStream.Write(Buf[1], Length(Buf));

FileToSend := TMemoryStream.Create;
// Open File with TMemorystream
FileToSend.LoadFromFile(ExtractFilePath(ParamStr(0)) + StrPas(filename^.chars));
// load it up
FileToSend.SaveToStream(THTTPCli(HTTPList[FIX2INT(id)]).SendStream);
// Dump out file to TMemorystream
FileToSend.Free;
// andddd free it up
if PostVar<>'' then Buf := InputText('variable',PostVar);
Buf := ConCat(buf,Boundry+'--'); {This is to signify the END of our transactions }
THTTPCli(HTTPList[FIX2INT(id)]).SendStream.Write(Buf[1], Length(Buf));

TMemoryStream(ResultList[FIX2INT(id)]).Clear;
THTTPCli(HTTPList[FIX2INT(id)]).RcvdStream := TMemoryStream(ResultList[FIX2INT(id)]);
THTTPCli(HTTPList[FIX2INT(id)]).SendStream.Seek(0,0);
THTTPCli(HTTPList[FIX2INT(id)]).URL := StrPas(URL^.chars);
WorkList[FIX2INT(id)] := '1';
THTTPCli(HTTPList[FIX2INT(id)]).PostAsync;
except
Error := 1;
end;
result := INT2FIX(Error);
end;



Posted By: FixxeR

Re: GS_HTTP/Peacekeeper-plugin - 11/16/06 03:49

This may be a stupid question to ask, but since you're executing a PHP file from the A6 Engine I thought I should. Do you have Apache/PHP running, or a background PHP interpreter, to execute the PHP code?

Edit:
Okay, I see now that you're executing the PHP file from a server. I'll start testing it to see if I can get it to work.

FixxeR
Posted By: Joey

Re: GS_HTTP/Peacekeeper-plugin - 11/16/06 10:33

good that i can read object pascal... uum, i don't see a reason for the fourth parameter, the string. it's not that obvious what it does, and i'm not that much into the http protocol to decipher what it actually does. i think that this gives you the possibility to actually post variables as with the html input fields. the rest seems clear to me since i've once written an asynchronous upload script in phython and php, writing the uploaded form data as-is (the raw multipart upload) in a file. your form field name is 'uploadFile1', so try $_FILE['uploadFile1'].

are you really sure that you have given the filename as relative path to your gamestudio exe?

could you post the return code of the function call? just curious wether the delphi dll throws an error or not.

joey.

ps: is it just me or has the coder of this dll an awful coding style?
Posted By: FixxeR

Re: GS_HTTP/Peacekeeper-plugin - 11/18/06 01:53

I think that the fourth variable is for the post method but, like Joey said, it isn't really used so it's difficult to tell.

FixxeR
Posted By: Anonymous

Re: GS_HTTP/Peacekeeper-plugin - 11/19/06 18:04

Has someone an idea how to pass (set up) a proxy with GS_HTTP/Peacekeeper-plugin?

thanx, mercuryus
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/26/06 09:53

well, nothing changed. http_return does not return anything, just an empty string, no error code.
i decided to write a mail directly to the creator, see if it helps.
Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/27/06 21:02

this is the official answer:

Quote:


Just use HTTP_PostFile2()? The forth variable in HTTP_PostFile() is for
sending name=value pairs in addition to the file.

The path of the file is:

ExtractFilePath(ParamStr(0)) + StrPas(filename^.chars)

Which means ExtractFilePath(c:\whatever\whatever\myacknex.exe) + filename.

In the case of preview or whatever in A6 the file would need to be in
the same directory as the acknex EXE which is the gstudio\bin dir. Also
if you include directory slashs in that filename you have to double them up.

So:
c:\program files\gstudio\bin\acknex.exe
c:\program files\gstudio\bin\gshttp.dll
c:\program files\gstudio\bin\images\myfile.jpg
c:\program files\gstudio\bin\myfile2.jpg
c:\program files\gstudio\myproject\whatever.wdl

HTTP_PostFile2(0,
'http://www.whatever.com/whatever.php','images\\myfile.jpg');


HTTP_PostFile2(0, 'http://www.whatever.com/whatever.php','myfile2.jpg');

Published it would be something like:
c:\program files\myproject\acknex.exe
c:\program files\myproject\gshttp.dll
c:\program files\myproject\images\myfile.jpg
c:\program files\myproject\myfile2.jpg
c:\program files\myproject\whatever.wdl


Something like that.

Also, the GS_Python plugin provides more robust HTTP stuff.

Thanks,
Cellulaer





now i do get a string back, it says "FAILURE", which is certainly fron the php script. something must be wrong there.

now, this is my code:

Code:

dll_handle = dll_open("GSHTTP.dll");
HTTP_Create(0);
HTTP_PostFile2 (0, "http://whateverurl/anonymus-upload.php", serversettings); //serversettings is a file namend "workstation1.bz3", a plain text file
while (HTTP_IsWorking(0)==1) {
wait(1);
}
HTTP_Results(0,results_str);
HTTP_Free(0);
dll_close(dll_handle);
wait(1);

////////////////////////////////////////////////this was the wdl code, now the php:

<?php
if (count($_FILES) && $_FILES['name']['error'])
{
$filename = $_FILES['name']['name'];
if (move_uploaded_file($_FILES['name']['tmp_name'], $filename)) {
echo "SUCCESS";
} else {
echo "FAILURE";
}
} else {
echo "FAILURE";
}
?>


Posted By: broozar

Re: GS_HTTP/Peacekeeper-plugin - 11/28/06 20:39

after changing everything into 'uploadFile1' (not everything of course, just the important vars) i still get the error and i am really lost. please help me once more. this is drivin me crazy...
Posted By: PrenceOfDarkness

Re: GS_HTTP/Peacekeeper-plugin - 05/20/07 04:47

Sorry to bring up such an old post.... but, i'm dieing to know... did anyone ever get GSHTTP to ever work?
Posted By: MMike

Re: GS_HTTP/Peacekeeper-plugin - 11/28/09 20:50

wish i would know.
Posted By: Damocles_

Re: GS_HTTP/Peacekeeper-plugin - 11/29/09 01:53

I just used the plugin recently in the Highscore for the JewelDrop game using A7
Works fine.
Posted By: MMike

Re: GS_HTTP/Peacekeeper-plugin - 11/29/09 17:28

downloading images too?
Posted By: MMike

Re: GS_HTTP/Peacekeeper-plugin - 11/29/09 17:28

lite -c?
© 2024 lite-C Forums