diff src/kaigo/horori/searcher/include/net.h @ 47:169936fed61b

small changes.
author pyon@macmini
date Tue, 21 Apr 2020 22:43:55 +0900
parents 20b42e2deae1
children 4e14902379da
line wrap: on
line diff
--- a/src/kaigo/horori/searcher/include/net.h	Sat Apr 18 21:10:29 2020 +0900
+++ b/src/kaigo/horori/searcher/include/net.h	Tue Apr 21 22:43:55 2020 +0900
@@ -1,5 +1,5 @@
 // Filename   : net.h
-// Last Change: 2020-03-30 ŒŽ 15:05:58.
+// Last Change: 2020-04-21 ‰Î 13:44:57.
 //
 #pragma once
 
@@ -73,10 +73,53 @@
 			file_ostream.Close();
 		}
 		ret = true;
+		//wxDELETE(httpStream);
 	}
 
-	//wxDELETE(httpStream);
 	get.Close();
 	return ret;
 };
 
+bool HttpPostFile(wxString addr, wxString port, wxString url, wxString file)
+{
+	bool ret = false;
+
+	wxMemoryBuffer buf;
+	wxByte b[8192];
+	wxFFile f;
+	if (!f.Open(file, wxT("rb"))) {
+        wxMessageBox(wxT("Cannot open file."));
+        return ret;
+    }
+	for (;;) {
+		size_t len = f.Read(b, sizeof(b));
+		if ((size_t)wxInvalidOffset == len) {
+			return ret;
+		}
+		if (len == 0) break; // success
+		buf.AppendData(b, len);
+	}
+	f.Close();
+
+	wxHTTP post;
+	post.SetTimeout(30);
+	post.SetFlags(wxSOCKET_WAITALL|wxSOCKET_BLOCK);
+	post.SetPostBuffer(wxT("application/gzip"), buf);
+
+	while (!post.Connect(addr, wxAtoi(port)))
+		wxSleep(1);
+
+	wxInputStream *httpStream = post.GetInputStream(url);
+	if (httpStream != NULL) {
+		wxString res;
+		wxStringOutputStream out_stream(&res);
+		httpStream->Read(out_stream);
+		wxDELETE(httpStream);
+		//wxMessageBox(res);
+		ret = true;
+	}
+
+	post.Close();
+	return ret;
+};
+