Home » U++ Library support » U++ MT-multithreading and servers » HttpRequest File Upload
Re: HttpRequest File Upload [message #39574 is a reply to message #39573] |
Sun, 31 March 2013 11:48 |
|
mirek
Messages: 13980 Registered: November 2005
|
Ultimate Member |
|
|
Brat wrote on Sat, 30 March 2013 16:11 | Okay,
i have to calculate the new Content-Length - how can i do this? strlen()? And how can i manipulate the Content-Length field?
#EDIT:
Okay, i created this class.
class MultiHTTP {
public:
MultiHTTP();
MultiHTTP(String boundary);
String GetContentType();
String GetBoundary();
void AddData(String name, String content);
void AddFile(String name, String filename, String mime, String content);
String GetRequest();
private:
String bound;
String req;
int64 Length;
};
MultiHTTP::MultiHTTP(){
bound = "---MULTIPART-BOUNDARY---" + AsString(Random()) + "---" + AsString(Random()) + "---";
req = bound + "\n";
}
MultiHTTP::MultiHTTP(String boundary){
bound = boundary;
req = bound + "\n";
}
String MultiHTTP::GetContentType(){
return "multipart/form-data, boundary=" + bound;
}
String MultiHTTP::GetBoundary(){
return bound;
}
void MultiHTTP::AddData(String name, String content){
req += "Content-Disposition: form-data; name=\"" + name +"\"\n\n";
req += content + "\n" + bound + "\n";
}
void MultiHTTP::AddFile(String name, String filename, String mime, String content){
req += "Content-Disposition: form-data; name=\"" + name + "\"; filename=\"" + filename + "\"\n";
req += "Content-Type: " + mime + "\n";
req += "Content-Transfer-Encoding: binary\n\n";
req += content + "\n" + bound + "\n";
}
String MultiHTTP::GetRequest(){
return req;
}
And my Code is
MultiHTTP request;
request.AddData("username", "USER");
request.AddData("password", "PASSWORD");
request.AddData("upload_session", session[0]);
request.AddData("chunk_no", "1");
request.AddData("chunk_number", "1");
request.AddData("filesize", AsString(Filesize));
request.AddData("finalize", "1");
request.AddFile("fn", file, "text/plain", LoadFile(file));
LOG(request.GetRequest());
HttpRequest req(session[1]);
req.POST();
req.ContentType(request.GetContentType());
req.PostData(request.GetRequest());
ret = req.Execute();
if(!req.IsSuccess()){
PromptOK("FAILED");
PromptOK(req.GetErrorDesc());
return;
}
LOG(ret);
My class created this POST data
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="username"
USERNAME
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="password"
PASSWORD
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="upload_session"
O1QQRHKMDIDI
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="chunk_no"
1
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="chunk_number"
1
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="filesize"
69
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="finalize"
1
---MULTIPART-BOUNDARY---657443953---2000568409---
Content-Disposition: form-data; name="fn"; filename="NeedIt.txt"
Content-Type: text/plain
Content-Transfer-Encoding: binary
Sonic Youth
Deftones
Death From Above 1979
(Andrew Jackson Jihad)
---MULTIPART-BOUNDARY---657443953---2000568409---
But the Request fails. i only got this error
socket(6) / recv: Connection reset by peer
Whats wrong?
|
Hard to say. Try HttpRequest::SetTrace.
Mirek
|
|
|
|
|
HttpRequest File Upload
By: Brat on Fri, 29 March 2013 13:23
|
|
|
Re: HttpRequest File Upload
By: Brat on Sat, 30 March 2013 11:50
|
|
|
Re: HttpRequest File Upload
By: mirek on Sat, 30 March 2013 12:13
|
|
|
Re: HttpRequest File Upload
By: Brat on Sat, 30 March 2013 12:44
|
|
|
Re: HttpRequest File Upload
By: mirek on Sat, 30 March 2013 12:51
|
|
|
Re: HttpRequest File Upload
By: Brat on Sat, 30 March 2013 21:11
|
|
|
Re: HttpRequest File Upload
By: mirek on Sun, 31 March 2013 11:48
|
|
|
Re: HttpRequest File Upload
By: Brat on Sun, 31 March 2013 20:41
|
|
|
Re: HttpRequest File Upload
By: mirek on Sat, 06 April 2013 10:05
|
|
|
Re: HttpRequest File Upload
By: mirek on Sat, 29 June 2013 20:53
|
|
|
Re: HttpRequest File Upload
By: Zbych on Mon, 14 October 2013 15:51
|
|
|
Re: HttpRequest File Upload
By: mirek on Mon, 14 October 2013 16:00
|
|
|
Re: HttpRequest File Upload
By: Zbych on Mon, 14 October 2013 16:47
|
|
|
Re: HttpRequest File Upload
By: mirek on Tue, 15 October 2013 07:44
|
|
|
Re: HttpRequest File Upload
By: forlano on Thu, 08 May 2014 14:35
|
|
|
Re: HttpRequest File Upload
By: forlano on Sun, 11 May 2014 22:17
|
Goto Forum:
Current Time: Thu May 16 09:39:17 CEST 2024
Total time taken to generate the page: 0.02848 seconds
|