components/webclient/src/webclient.c
int webclient_get(struct webclient_session *session, const char *URI)
{
    int rc = WEBCLIENT_OK;
    int resp_status = 0;

    if (!session || !URI)
    {
        return WEBCLIENT_ERROR;
    }

    rc = webclient_connect(session, URI);
    if (rc != WEBCLIENT_OK)
    {
        /* connect to webclient server failed. */
        return rc;
    }

    rc = webclient_send_header(session, WEBCLIENT_GET);
    if (rc != WEBCLIENT_OK)
    {
        /* send header to webclient server failed. */
        return rc;
    }

    /* handle the response header of webclient server */
    resp_status = webclient_handle_response(session);
    if (resp_status > 0)
    {
        const char *location = webclient_header_fields_get(session, "Location");

        /* relocation */
        if ((resp_status == 302 || resp_status == 301) && location)
        {
            webclient_close(session);
            return webclient_get(session, location);
        }
        else if (resp_status != 200)
        {
            // "get failed, handle response(%d) error!", resp_status
            return resp_status;
        }
    }

    return resp_status;
}
/**
 *  send GET request to http server and get response header.
 *
 * @param session webclient session
 * @param URI input server URI address
 * @param header GET request header
 *             = NULL: use default header data
 *            != NULL: use custom header data
 *
 * @return <0: send GET request failed
 *         >0: response http status code
 */
send GET request to http server and get response header.
@param session webclient session
@param URI input server URI address
@param header GET request header
= NULL: use default header data
!= NULL: use custom header data

@return <0: send GET request failed
>0: response http status code
send GET request to http server and get response header . @param session webclient session @param URI input server URI address @param header GET request header = NULL : use default header data ! = NULL : use custom header data @return <0 : send GET request failed > 0 : response http status code
int webclient_get(struct webclient_session *session, const char *URI)
{
    int rc = WEBCLIENT_OK;
    int resp_status = 0;
    if (!session || !URI)
    {
        return WEBCLIENT_ERROR;
    }
    rc = webclient_connect(session, URI);
    if (rc != WEBCLIENT_OK)
    {
        return rc;
    }
    rc = webclient_send_header(session, WEBCLIENT_GET);
    if (rc != WEBCLIENT_OK)
    {
        return rc;
    }
    resp_status = webclient_handle_response(session);
    if (resp_status > 0)
    {
        const char *location = webclient_header_fields_get(session, "Location");
        if ((resp_status == 302 || resp_status == 301) && location)
        {
            webclient_close(session);
            return webclient_get(session, location);
        }
        else if (resp_status != 200)
        {
            return resp_status;
        }
    }
    return resp_status;
}
int webclient_get ( struct webclient_session * session , const char * URI ) { int rc = WEBCLIENT_OK ; int resp_status = 0 ; if ( ! session || ! URI ) { return WEBCLIENT_ERROR ; } rc = webclient_connect ( session , URI ) ; if ( rc != WEBCLIENT_OK ) { return rc ; } rc = webclient_send_header ( session , WEBCLIENT_GET ) ; if ( rc != WEBCLIENT_OK ) { return rc ; } resp_status = webclient_handle_response ( session ) ; if ( resp_status > 0 ) { const char * location = webclient_header_fields_get ( session , " " ) ; if ( ( resp_status == 302 || resp_status == 301 ) && location ) { webclient_close ( session ) ; return webclient_get ( session , location ) ; } else if ( resp_status != 200 ) { return resp_status ; } } return resp_status ; }
send GET request to http server and get response header.
send GET request to http server and get response header .
/* connect to webclient server failed. */ /* send header to webclient server failed. */ /* handle the response header of webclient server */ /* relocation */ // "get failed, handle response(%d) error!", resp_status