
28.07.2009, 10:36
|
|
Познавший АНТИЧАТ
Регистрация: 05.03.2007
Сообщений: 1,985
С нами:
10097606
Репутация:
3349
|
|
Еще были ошибки в коде - не в том месте закрывались хендлы.
Проводим простой следственный эксперимент.
Берем PHP файл через который будем грузить чтонить
PHP код:
<form action="?act=upload" method="POST" enctype="multipart/form-data">
<input type="text" name="info">
<input type="file" name="myfile">
<input type="submit" value="UPLOAD">
</form>
<?
if ($_GET['act'] == 'upload')
{
$name = $_FILES['myfile']['name'];
$myfile=$_FILES['myfile']['tmp_name'];
if (!file_exists($myfile))
{
echo '<h3>Error</h3>';
}
else
{
Copy($myfile, $name);
echo "<h3>OK</h3><br>{$_POST['info']}";
}
}
?>
Через снифер получаем данные:
POST /1.php?act=upload HTTP/1.1
Host: 127.0.0.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9) Gecko/2008052906 Firefox/3.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: ru,en-us;q=0.7,en;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: windows-1251,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://127.0.0.1/1.php
Content-Type: multipart/form-data; boundary=---------------------------41184676334
Content-Length: 769
-----------------------------41184676334
Content-Disposition: form-data; name="info"
infodata
-----------------------------41184676334
Content-Disposition: form-data; name="myfile"; filename="test.txt"
Content-Type: text/plain
this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file this is test file
-----------------------------41184676334--
Теперь на основании этих данных очень просто построить запрос.
Код:
procedure TForm1.Button1Click(Sender: TObject);
var
hOpenHandle, hConnectHandle, hResourceHandle: Pointer;
boundary:string;
header, data:string;
begin
hOpenHandle := InternetOpen(nil, 0, nil, nil, 0);
if hOpenHandle <> nil then
begin
hConnectHandle := InternetConnect(hOpenHandle, '127.0.0.1', 80, nil, nil, 3, 0, 0);
if hConnectHandle <> nil then
begin
hResourceHandle := HttpOpenRequest(hConnectHandle, 'POST', '/1.php?act=upload', nil, nil, nil, INTERNET_FLAG_KEEP_CONNECTION, 0);
if hResourceHandle <> nil then
begin
boundary := inttostr(random(65355))+inttostr(random(65355))+inttostr(random(65355));
header := 'Content-Type: multipart/form-data; boundary='+boundary;
data := '--'+boundary+#13#10+
'Content-Disposition: form-data; name="info"'#13#10#13#10+edit1.Text+#13#10+
'--'+boundary+#13#10+
'Content-Disposition: form-data; name="myfile"; filename="test.txt"'#13#10+
'Content-Type: text/plain'#13#10#13#10+memo1.Text+#13#10+
'--'+boundary+'--';
HttpSendRequest(hResourceHandle, @header[1], length(header), @data[1], length(data));
InternetCloseHandle(hResourceHandle);
end;
InternetCloseHandle(hConnectHandle);
end;
InternetCloseHandle(hOpenHandle);
end;
end;
|
|
|