Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/153.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/windows/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
htttps中的垃圾字符获取响应 我面临着一个奇怪的情况,一个Windows应用程序(OCX控件)用C++编写,直到2天前才正常运行。未向应用程序添加任何更新。然后突然,它开始在与远程测试服务器的通信中出错。基本上,错误在于在对GET请求的响应中,我看到了这样的垃圾字符:ñòWo††BA etc_C++_Windows_Https_Fiddler - Fatal编程技术网

htttps中的垃圾字符获取响应 我面临着一个奇怪的情况,一个Windows应用程序(OCX控件)用C++编写,直到2天前才正常运行。未向应用程序添加任何更新。然后突然,它开始在与远程测试服务器的通信中出错。基本上,错误在于在对GET请求的响应中,我看到了这样的垃圾字符:ñòWo††BA etc

htttps中的垃圾字符获取响应 我面临着一个奇怪的情况,一个Windows应用程序(OCX控件)用C++编写,直到2天前才正常运行。未向应用程序添加任何更新。然后突然,它开始在与远程测试服务器的通信中出错。基本上,错误在于在对GET请求的响应中,我看到了这样的垃圾字符:ñòWo††BA etc,c++,windows,https,fiddler,C++,Windows,Https,Fiddler,我用于HTTP请求的函数是: TCHAR* openUrlFunction(TCHAR *strServer, TCHAR *strPath, TCHAR *userAgent){ HINTERNET httpSession = NULL; HINTERNET httpConnect = NULL; HINTERNET httpRequest = NULL; HINTERNET hFile = NULL; BOOL resD

我用于HTTP请求的函数是:

TCHAR* openUrlFunction(TCHAR *strServer, TCHAR *strPath, TCHAR *userAgent){

    HINTERNET   httpSession = NULL;
    HINTERNET   httpConnect = NULL;
    HINTERNET   httpRequest = NULL;
    HINTERNET   hFile = NULL;
    BOOL        resDownload = FALSE;
    TCHAR       bufferIdent[60] = { 0 };
    TCHAR       bufferMirror[500] = { 0 };
    TCHAR       szURL[200] = { 0 };
    TCHAR       sError[7] = { 0 };
    DWORD       dwFlags;
    //  DWORD       dwTimeOut = 25000;
    DWORD       dwBuffLen = sizeof(dwFlags);
    int         i = 0;
    DWORD       dwRead, error;
    int         len;
    TCHAR       *res1;
    TCHAR       delimeter[6] = _T("\f\n\r\t\v");

    HRESULT resCat;

    
    bufferIdent[0] = '\0';
    bufferMirror[0] = '\0';
    szURL[0] = '\0';

    std::string ss;

    httpSession = InternetOpen(strAgent, INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0); // header 

    if (httpSession)
    {
        httpConnect = InternetConnect(httpSession, strServer, INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0); 

        if (httpConnect)
        {
            httpRequest = HttpOpenRequest(httpConnect, "GET", strPath, NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);  parametros.

            if (HttpSendRequest(httpRequest, NULL, 0, NULL, 0)) {  
                if (httpRequest)
                {
                    while (InternetReadFile(httpRequest, bufferMirror, 499, &dwRead)) // Se lee el retorno
                    {
                        if (dwRead == 0)
                            break;

                        StrTrim(bufferMirror, delimeter);

                        while (bufferMirror[i] != NULL){  

                            if (bufferMirror[i] != char(10))
                                ss = ss + bufferMirror[i];
                            i++;
                            if (bufferMirror[i] == char(10))  
                                break;
                        }
                        i = 0;
                    }
                }
            }
            else{

                error = GetLastError();
                _stprintf_s(sError, 7, _T("%d"), error);
                InternetCloseHandle(httpRequest);
                InternetCloseHandle(httpConnect);
                InternetCloseHandle(httpSession);
                return sError;
            }
            InternetCloseHandle(httpRequest);  
        }
        InternetCloseHandle(httpConnect);
    }
    InternetCloseHandle(httpSession);

 

    len = ss.length();

    if (len == 0){
        return NULL;
    }
    res1 = new TCHAR[len + 1];

    resCat = StringCchCopyN(res1, len + 1, ss.c_str(), len);

    if (!SUCCEEDED(resCat))
        return NULL;

    return res1;
}
有趣的是,我决定监控流量,所以我在发生问题的同一台机器(Windows 10)上安装了Fiddler。启动Fiddler后,我对应用程序进行了测试,瞧,响应清晰、格式良好,没有垃圾字符出现

我怀疑安装的Fiddler Everywhere证书与结果有关。因此,如果我关闭Fiddler并进行新的测试,我将再次收到垃圾字符

我已经检查了计算机中的TLS配置,没有任何问题。我不确定Windows更新是否会导致这种情况

我们有3台机器,问题发生在3台机器中的2台上。它们都是Windows 10,但可能有不同的更新


另一个重要的问题是,服务器是用于测试的,客户端没有安装任何SSL证书。

在研究了这个问题之后,我发现问题的根源更多地与以下事实有关:其中一个变量没有正确初始化,在http请求之前,此变量可能包含垃圾字符,因此该变量包含的垃圾会影响流程的后续步骤。另一件事是WININET的连接问题在安装正确的SSL证书后得到了解决。即使在设置了一些标志以绕过SSL验证之后,也不起作用。仅当服务器配置了SSL证书时,连接才可能进行。

您只是检查
dwRead
是否为零,然后假设缓冲区中不是
\0
的所有其他内容都是数据,但如果
dwRead==1
则缓冲区中只有第一个字节是已读取的实际数据,另一个
499-dwRead
字节是垃圾。您需要正确使用
dwRead
来确定每次调用
InternetReadFile
时将多少字节读入缓冲区。