回答編集履歴
2
誤って投稿したため削除しました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
誤って投稿したため削除しました。
|
1
自己解決の投稿欄を間違ったため削除しました。
test
CHANGED
@@ -1,143 +1 @@
|
|
1
|
-
自己解決できました。
|
2
|
-
|
3
|
-
HTTPについての知識が断片的であり、リクエストの構造を把握していなかったことが原因でした。
|
4
|
-
|
5
|
-
以下のサイトでHTTPリクエストについて調べたところ、ヘッダ行とボディ部を混同していたことがわかりました。
|
6
|
-
|
7
|
-
[http://www.yoheim.net/blog.php?q=20120611](http://www.yoheim.net/blog.php?q=20120611)
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
そして、以下のサイトを参考に、それぞれのパラメータをバウンダリ文字列で区切った文字列をボディ部にsetRequestDataでセットしたところ、意図通りのデータを取得することが出来ました。
|
12
|
-
|
13
|
-
[http://d.hatena.ne.jp/satox/20110726/1311665904](http://d.hatena.ne.jp/satox/20110726/1311665904)
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
1
|
+
自己解決の投稿欄を間違ったため削除しました。
|
18
|
-
|
19
|
-
※部分的なものなので正常に動作するかは保証出来ません。
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
```C++
|
24
|
-
|
25
|
-
void cGameManager::Upload(string path) {
|
26
|
-
|
27
|
-
HttpRequest* request = new HttpRequest();
|
28
|
-
|
29
|
-
string url = "http://***.jp/";
|
30
|
-
|
31
|
-
request->setUrl(url.c_str());
|
32
|
-
|
33
|
-
request->setRequestType(HttpRequest::Type::POST);
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
string boundary = GetRandomBoundary();
|
38
|
-
|
39
|
-
//ヘッダ
|
40
|
-
|
41
|
-
vector<string> headers;
|
42
|
-
|
43
|
-
headers.push_back("Content-Type: multipart/form-data; boundary=" + boundary);
|
44
|
-
|
45
|
-
request->setHeaders(headers);
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
//ボディー
|
50
|
-
|
51
|
-
map<string, string> postData = map<string, string>();
|
52
|
-
|
53
|
-
postData["ownerId"] = "1";
|
54
|
-
|
55
|
-
postData["action"] = "upload";
|
56
|
-
|
57
|
-
string postString = GetPostString(postData, boundary);
|
58
|
-
|
59
|
-
postString += GetMultipartData(path, boundary);
|
60
|
-
|
61
|
-
request->setRequestData(postString.c_str(), postString.length());
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
I(HttpClient)->send(request);
|
66
|
-
|
67
|
-
request->release();
|
68
|
-
|
69
|
-
}
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
string GetPostString(map<string, string>& postMap, string boundary) {
|
74
|
-
|
75
|
-
if (postMap.size() == 0) {
|
76
|
-
|
77
|
-
return "";
|
78
|
-
|
79
|
-
}
|
80
|
-
|
81
|
-
string postString = "";
|
82
|
-
|
83
|
-
postString += "\r\n--" + boundary;
|
84
|
-
|
85
|
-
for (auto iter = postMap.begin(); iter != postMap.end(); ++iter) {
|
86
|
-
|
87
|
-
postString += "\r\nContent-Disposition: form-data; name=\"" + iter->first + "\"";
|
88
|
-
|
89
|
-
postString += "\r\n\r\n" + iter->second;
|
90
|
-
|
91
|
-
if ((++iter)-- != postMap.end()) {
|
92
|
-
|
93
|
-
postString += "\r\n--" + boundary;
|
94
|
-
|
95
|
-
}
|
96
|
-
|
97
|
-
}
|
98
|
-
|
99
|
-
postString += "\r\n--" + boundary;
|
100
|
-
|
101
|
-
return postString;
|
102
|
-
|
103
|
-
}
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
string GetMultipartData(string path, string boundary) {
|
108
|
-
|
109
|
-
auto fileData = I(FileUtils)->getDataFromFile(path);
|
110
|
-
|
111
|
-
string binary;
|
112
|
-
|
113
|
-
GetFileBinary(path, binary);
|
114
|
-
|
115
|
-
char length[1024];
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
string body = "";
|
120
|
-
|
121
|
-
body += "\r\n--" + boundary;
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
body += "\r\n" + string(length);
|
126
|
-
|
127
|
-
body += "\r\nContent-disposition: form-data; name=\"uploadFile\"; filename=\"file.zip\"";
|
128
|
-
|
129
|
-
body += "\r\nContent-Type: application/zip";
|
130
|
-
|
131
|
-
body += "\r\n\r\n" + binary;
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
body += "\r\n--" + boundary;
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
return body;
|
140
|
-
|
141
|
-
}
|
142
|
-
|
143
|
-
```
|