blockchain , sdchain cpp sdk and demo

Dependencies:   EthernetInterface mbed-rtos mbed uniqueCPUID

Fork of bcsdk by SDchain C Plus Plus Team

Revision:
10:aabd720e632c
Parent:
8:f2a567ee3a46
Child:
12:1b24ea479a59
--- a/Client.cpp	Wed Sep 27 01:18:12 2017 +0000
+++ b/Client.cpp	Fri Nov 03 01:07:32 2017 +0000
@@ -62,6 +62,55 @@
 	return ret;
 }
 
+string Client::get_content(const string & strRep)
+{
+	string content = "";
+	content = strRep.substr(strRep.find("\r\n\r\n") + sizeof("\r\n\r\n") - 1); //sizeof("\r\n\r\n") 5
+	if (content.at(0) != '{' && content.at(0) != '[')
+	{
+		content = content.substr(content.find("\r\n") + sizeof("\r\n") - 1);
+	}
+	return content;
+}
+
+bool Client::unbuild_post_raw(const string & strRep, int & content_length, string & url,string & content)
+{
+	bool ret = true;
+	
+	content_length = get_content_length(strRep);
+	content = strRep.substr(strRep.find("\r\n\r\n"));
+
+	if (strRep.find("200 OK") < 0)
+	{
+		ret = false;
+	}
+	
+	return ret;
+}
+
+int Client::get_content_length(const string & strRaw)
+{
+	int len = -1; // 表示没找到
+/*/
+	string strRaw = "\
+HTTP/1.1 200 OK\r\n\
+Blockchain-Id: 13804cbf90e019cc0bcc7243828298492f5d0d87423f776181069eb9af9b2071\r\n\
+Chain-Request-Id: f90965648d6aeb6075e3\r\n\
+Content-Length: 145\r\n\
+X-Frame-Options: DENY\r\n\
+\r\n\r\n\
+{\"alias\":\"t_key_1\",\"xpub\":\"1c926b1e7a88496e5bd7e29736f9ca85c5386bb995c95412b1084ddc1ab5f80e49e7aea51f08b36b3773baa6277c5902f2034d36315b32bf96a3082c048225d5\"}\
+\n";
+*/
+	string str = "";
+	int pos = strRaw.find("Content-Length:") + sizeof("Content-Length:");
+	str = strRaw.substr(pos);
+	pos = str.find("\r\n");
+	str = str.substr(0,pos);
+	len = atoi(str.c_str());
+
+	return len;
+}												 
 int Client::http_post(const string & url,const string & content,string & strOut)
 {
 	string post_raw = "";
@@ -143,9 +192,10 @@
 		//get errno
 		return ret;
 	}
-
+#define DEBUG_LOG 1
 #ifdef DEBUG_LOG
-	cout<< ">>>>>>>>>>HTTP Request (Length = "<< strReq.length() << "):\n" << strReq << endl;
+	//cout<< ">>>>>>>>>>HTTP Request (Length = "<< strReq.length() << "):\n" << strReq << endl;
+	printf(">>>>>>>>>>HTTP Request (Length = %d):\r\n%s\r\n", strReq.length(), strReq.c_str());
 #endif
 
 
@@ -172,7 +222,8 @@
 	strOut = strRep;
 
 #ifdef DEBUG_LOG
-	cout<< ">>>>>>>>>>HTTP Response (Length = "<< strRep.length() << "):\n" << strRep << endl;
+	//cout<< ">>>>>>>>>>HTTP Response (Length = "<< strRep.length() << "):\n" << strRep << endl;
+	printf(">>>>>>>>>>HTTP Response (Length = %d):\r\n%s\r\n", strRep.length(), strRep.c_str());
 #endif
 
 	// Clean up