ML307C GET请求失败

错误码650,未知错误

域名不需要加端口,注释掉相应部分

int app_http_url_check(char *http_url, char *http_host, uint32_t host_size, char *http_path, uint32_t path_size)
{
    char http_host_temp[256] = {0}, http_path_temp[256] = {0};
    char *offset = NULL;
    int port = 0;

    if (strncmp(http_url, "http://", strlen("http://")) == 0)
    {
        offset = strchr(http_url + strlen("http://"), '/');
        if (offset == NULL)
        {
            cm_log_printf(0,"http url format is error:%s\n", http_url);
            return -1;
        }
        strcpy(http_path_temp, offset);
        strncpy(http_host_temp, http_url, strlen(http_url) - strlen(offset));
    }
    else
    {
        offset = strchr(http_url, '/');
        if (offset == NULL)
        {
            cm_log_printf(0,"http url format is error:%s\n", http_url);
            return -1;
        }
        strcpy(http_path_temp, offset);
        strcpy(http_host_temp, "http://");
        strncpy(http_host_temp + strlen("http://"), http_url, strlen(http_url) - strlen(offset));
    }

    // if (sscanf(http_host_temp, "http://%*[^:]:%d", &port) != 1) // 没有port,添加默认port口80
    // {
    //     strcat(http_host_temp, ":80");
    // }

    if (host_size < strlen(http_host_temp) || path_size < strlen(http_path_temp))
    {
        cm_log_printf(0,"http host or path size not enough\n");
        return -2;
    }

    // -------- 去掉前缀 http:// --------
    const char *host_no_prefix = http_host_temp;
    if (strncmp(http_host_temp, "http://", strlen("http://")) == 0)
    {
        host_no_prefix = http_host_temp + strlen("http://");
    }

    strncpy(http_host, host_no_prefix, strlen(host_no_prefix));
    http_host[strlen(host_no_prefix)] = '\0';

    strncpy(http_path, http_path_temp, strlen(http_path_temp));
    http_path[strlen(http_path_temp)] = '\0';

    //cm_log_printf(0,"[FOTA]host addr:%s,url:%s\n", http_host, http_path);

    return 0;
}

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值