add DEBUG switch and fix win build error

This commit is contained in:
zhangzifa
2019-02-21 11:20:28 +08:00
committed by TonyZZF
parent 6a5f788210
commit eb7ab33440
7 changed files with 65 additions and 13 deletions

View File

@@ -76,7 +76,12 @@ string base64_encode(const unsigned char *src, size_t len) {
string imageBase64(string file) {
FILE* img = fopen(file.c_str(), "rb");
FILE* img = nullptr;
#ifdef _WIN32
fopen_s(&img, file.c_str(), "rb");
#else
img = fopen(file.c_str(), "rb");
#endif
if (!img) {
perror("open file error");
return "";
@@ -166,8 +171,14 @@ int main(int argc, char** argv) {
char dir[1024];
utils.get_dir_exec(dir, nullptr);
#ifdef _WIN32
// windows binary has an extra Release/Debug/... dir
string image1_path = string(dir) + "\\..\\1.jpg";
string image2_path = string(dir) + "\\..\\2.jpg";
#else
string image1_path = string(dir) + "1.jpg";
string image2_path = string(dir) + "2.jpg";
#endif
picList[base64_encode((u8_t*)jpg1.c_str(), jpg1.size())] = imageBase64(image1_path);
picList[base64_encode((u8_t*)jpg2.c_str(), jpg2.size())] = imageBase64(image2_path);

View File

@@ -23,9 +23,11 @@ int main(int argc, char** argv) {
request.setDomain("nlp.cn-shanghai.aliyuncs.com");
request.setResourcePath("/nlp/api/wordsegment/general");
request.setHttpMethod(HttpRequest::Post);
const char * data = "{\"lang\":\"ZH\",\"text\":\"Iphone is a bad choice 专用数据线\"}";
request.setContent(data, strlen(data));
// if windows, Chinese character will result in build error.
const std::string data = "{\"lang\":\"ZH\",\"text\":\"Iphone is a good choice.\"}";
request.setContent(data.c_str(), data.size());
request.setHeaderParameter("Content-Type", "application/json;chrset=utf-8");
request.setHeaderParameter("Accept", "application/json");
request.setVersion("2018-04-08");