Интересует вопрос, как в точности повторить такой запрос
Делать пытался так
Но..
C#:
POST https://server.com HTTP/1.1
Content-Type: multipart/form-data; boundary=c6c302b53b6645cc88c35c9cdfb85c6e
Content-Length: 124148
Host: server.com
Connection: Keep-Alive
Accept-Encoding: gzip
--c6c302b53b6645cc88c35c9cdfb85c6e
Content-Disposition: form-data; name="id"; filename="user"
Content-Type: image/*
Content-Length: 123156
{фотка}
--c6c302b53b6645cc88c35c9cdfb85c6e
Content-Disposition: form-data; name="from_id"
Content-Length: 9
132869629
--c6c302b53b6645cc88c35c9cdfb85c6e--
Делать пытался так
C#:
string path = @"D:\001.jpg";
FileInfo strFileInfo = new FileInfo(path);
string fileName = strFileInfo.Name;
long fileLength = strFileInfo.Length;
int fromIdLength = fromId.Length;
string data = "--" + boundary;
data += Environment.NewLine + "Content-Disposition: form-data; name=\"id\"; filename=\"user\"";
data += Environment.NewLine + "Content-Type: image/*";
data += Environment.NewLine + $"Content-Length: {fileLength}";
data += Environment.NewLine + Environment.NewLine + path;
data += Environment.NewLine + "--" + boundary;
data += Environment.NewLine + "Content-Disposition: form-data; name=\"from_id\"";
data += Environment.NewLine + $"Content-Length: {fromIdLength}";
data += Environment.NewLine + Environment.NewLine + fromId;
data += Environment.NewLine + "--" + boundary + "--" + Environment.NewLine;
string s = ZennoPoster.HTTP.Request(
InterfacesLibrary.Enums.Http.HttpMethod.POST,
url: "https://server.com/",
content: data,
contentPostingType: "multipart/form-data; boundary=" + boundary,
Encoding: "UTF-8",
respType: ZennoLab.InterfacesLibrary.Enums.Http.ResponceType.BodyOnly,
Timeout: 30000,
UserAgent: userAgent,
proxy: proxy
);
- Если указывать filename="user" без расширения, Content-Type меняется на application/octet-stream. Параметр filename должен всегда быть равен user, как бы там файл не назывался.
- Content-Length вообще пропадает из запроса.
- Ну и еще меняется порядок, сначала секция с информацией о файле становится последней, а нужно чтобы была первой.