Fork HTTPClient and Modfiy code for mbed 6.0

Dependents:   mbed-demo-http-get-json

Files at this revision

API Documentation at this revision

Comitter:
quxiaorui
Date:
Sun Nov 08 10:33:36 2020 +0000
Parent:
50:1c1409029b05
Commit message:
remove unnecessary annotation.

Changed in this revision

HTTPClient.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/HTTPClient.cpp	Sun Nov 08 02:49:01 2020 +0000
+++ b/HTTPClient.cpp	Sun Nov 08 10:33:36 2020 +0000
@@ -52,7 +52,6 @@
 
 #include "HTTPClient.h"
 
-//HTTPClient::HTTPClient() :
 HTTPClient::HTTPClient(NetworkInterface *interface) : //modify for mbed 6.0
     m_sock(), m_basicAuthUser(NULL), m_basicAuthPassword(NULL), 
     m_nCustomHeaders(0), m_httpResponseCode(0), 
@@ -222,7 +221,6 @@
 
         //Connect
         DBG("Connecting socket to server");
-        //ret = m_sock.connect(host, port); // modify for mbed 6.0
         m_sock.open(net);
         SocketAddress a;
         net->gethostbyname(host, &a);
@@ -235,7 +233,7 @@
             return HTTP_CONN;
         }
         else {
-            printf("Connect server %s:%d\n",host,port);
+            DBG("Connect server %s:%d",host,port);
         }
         // Send request
         DBG("Sending request");
@@ -273,7 +271,6 @@
             ret = send(buf);
             if (ret) {
                 ERR("closing");
-                //wait_ms(50); 
                 ThisThread::sleep_for(50);// modify for mbed 6.0
                 m_sock.close();
                 ERR("Could not write request");
@@ -556,7 +553,6 @@
     DBG("Trying to read between %d and %d bytes", minLen, maxLen);
     size_t readLen = 0;
 
-    //if (!m_sock.is_connected()) {
     if (net->get_connection_status() != 1) { // modify for mbed 6.0
         WARN("Connection was closed by server");
         return HTTP_CLOSED; //Connection was closed by server
@@ -566,15 +562,11 @@
     while (readLen < maxLen) {
         if (readLen < minLen) {
             DBG("Trying to read at most %4d bytes [not Blocking, %d] %d,%d", minLen - readLen, 
-                m_timeout, minLen, readLen);
-            //m_sock.set_blocking(false, m_timeout);
-            //ret = m_sock.receive_all(buf + readLen, minLen - readLen);            
+                m_timeout, minLen, readLen);           
             ret = m_sock.recv(buf + readLen, minLen - readLen);// modify for mbed 6.0
         } else {
             DBG("Trying to read at most %4d bytes [Not blocking, %d] %d,%d", maxLen - readLen, 
                 0, maxLen, readLen);
-            //m_sock.set_blocking(false, 0);
-            //ret = m_sock.receive(buf + readLen, maxLen - readLen);
             ret = m_sock.recv(buf + readLen, maxLen - readLen);// modify for mbed 6.0
         }
 
@@ -583,7 +575,6 @@
         } else if ( ret == 0 ) {
             break;
         } else {
-            //if (!m_sock.is_connected()) {
             if (net->get_connection_status() != 1) { // modify for mbed 6.0
                 ERR("Connection error (recv returned %d)", ret);
                 *pReadLen = readLen;
@@ -592,7 +583,6 @@
                 break;
             }
         }
-        //if (!m_sock.is_connected()) {
         if (net->get_connection_status() != 1) { // modify for mbed 6.0
             break;
         }
@@ -611,15 +601,11 @@
     DBG("send(\r\n%s,%d)", buf, len);
     size_t writtenLen = 0;
 
-    //if(!m_sock.is_connected()) { 
     if (net->get_connection_status() != 1) { // modify for mbed 6.0
         WARN("Connection was closed by server");
         return HTTP_CLOSED; //Connection was closed by server
     }
-    //DBG("a");
-    //m_sock.set_blocking(false, m_timeout);
     DBG("b");
-    //int ret = m_sock.send_all(buf, len);
     int ret = m_sock.send(buf, len);// modify for mbed 6.0
     if(ret > 0) {
         writtenLen += ret;