【发布时间】:2019-12-10 22:04:06
【问题描述】:
使用德尔福 10.1。 需要发送图片到这个网站:www.flagma.ru
在嗅探器请求时:
URL:https://flagma.ru/messageuploadphoto.php?qqfile=111.jpg
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3
Content-Type: application/octet-stream
Referer: https://flagma.ru/my/1538481/podat-obyavlenie.html
X-File-Name:111.jpg
X-Mime-Type: image/jpeg
X-Requested-With: XMLHttpRequest
我的 Delphi 尝试:
http.Request.ContentType := 'application/octet-stream';
http.Request.Accept := '*/*';
http.Request.AcceptLanguage := 'ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7';
http.Request.AcceptEncoding := 'gzip, deflate';
http.Request.Referer := 'https://flagma.ru/my/1538481/podat-obyavlenie.html';
fnShort := ExtractFileName(fn); // fn - full image file
url := 'https://flagma.ru/messageuploadphoto.php?qqfile=' + fnShort;
http.Request.CustomHeaders.AddValue('X-Mime-Type', 'image/jpeg');
http.Request.CustomHeaders.AddValue('X-File-Name', fnShort);
http.Request.CustomHeaders.AddValue('X-Requested-With', 'XMLHttpRequest');
(* it is wrong way
a := TStringStream.Create(tempa);
formData := TIdMultiPartFormDataStream.Create;
formData.Clear;
formData.AddFile('qqfile', fn, GetMIMETypeFromFile(fn));
try
http.Post(url, formData, a);
except
on E: EIdException do
begin
response := '';
end;
end;
formData.Free;
response := utf8Decode(a.DataString);
*)
解决方案就是:response := http.Post(url, fn);
并且出现错误:Imagу 的宽度和高度都很小。但是在浏览器中相同的文件是可以的。
【问题讨论】:
-
您制作了一个多部分表单数据,其中文件只是其中一个字段,但在 mimetype 中您专门设置了
image/jpeg。那碰撞。要么只发送一个图像,然后将其直接加载到请求正文中,要么创建多部分表单数据并让请求标头实际指定它是多部分表单数据。你需要哪一个我不知道。这取决于接收请求的进程。 -
谢谢!决定只是:response := http.Post(url, fn);