Hi all,

We have placed a file named 檔名.txt into
the \apache-tomcat-8.0.43\webapps\Apps folder. And our client app can
retrieve the file by an HTTP GET request from the URL, for example,
http://192.168.1.1/Apps/檔名.txt (The 檔名 are two Chinese words)

When it was on tomcat v8.0.23, everything works fine. However, after we
have migrated to the v8.0.43, the client app will receive response with
HTTP 400 Bad Request. The code that our client app used as below. Looks
like that it didn't encode the URL path and only translate the whitespace
to %20.

Is there any solution that we can configure the tomcat 8.0.43 to make this
case works as usual(On tomcat v8.0.23), since there are lots of client
app deployed?

        SpaceToTwenty(szServerPath, szBuf, MAXURLSIZE);

        memset(szServerPath, 0, MAXURLSIZE);

        strcpy(szServerPath, szBuf);



        memset(szSendBuf, 0, SEND_BUF_SIZE);

        // the buffer for sending to the socket

        sprintf(szSendBuf, "GET %s HTTP/1.1\r\nHost:%s\r\n"

                           "Accept:
text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n"

                           "Accept-Language: zh-tw,en-us;q=0.7,en;q=0.3\r\n"

                           "Accept-Encoding: gzip, deflate\r\n"

                           "Connection: keep-alive\r\n\r\n",

                           szServerPath, szServerIP);

        LOG(LOG_ERROR, "[DL_Download] szServerPath: %s, szServerIP: %s,",

                        szServerPath, szServerIP);

        // create a socket for sending request

        SockCtx = SOCKET_Create(szServerIP, iServerPort, bSSLEnable,
CERTF_PATH);

        if (SockCtx == NULL)

        {

                LOG(LOG_ERROR, "[DL_Download] Socket Create Error!!!\n");

                iReturn = _ERROR;

                goto FUNC_EXIT;

        }



        SOCKET_Send(SockCtx, szSendBuf, strlen(szSendBuf));

        memset(szRecvBuf, 0, RECV_BUF_SIZE);

        iRecvBytes = SOCKET_Recv(SockCtx, szRecvBuf, sizeof(szRecvBuf));

        if (iRecvBytes <= 0)

        {

                LOG(LOG_ERROR, "[DL_Download] Socket Recv Error!!!
iRecvBytes = %d\n",iRecvBytes);

                iReturn = _ERROR;

                goto FUNC_EXIT;

        }



        memset(szHttpStatus, 0, sizeof(szHttpStatus));

        strncpy(szHttpStatus, szRecvBuf, strstr(szRecvBuf, "\r\n") -
szRecvBuf);

        // here it will receive the HTTP 400 Bad Request on the tomcat
v8.0.43

        // the szHttpStatus is 400

        if (strstr(szHttpStatus, "200 OK") == NULL)

        {

                LOG(LOG_ERROR, "[DL_Download] Http Status != 200, Status =
%s\n",szHttpStatus);

                iReturn = _ERROR;

                goto FUNC_EXIT;

        }



int SpaceToTwenty(char* szSrc, char* szDst, int iLen)

{

        int iReturn = _SUCCESS;

        char* c1;

        char* c2;

        char* c;

        int new_string_length = 0;



        for (c = szSrc; *c != '\0'; c++)

        {

                if (*c == ' ')

                        new_string_length += 2;

                new_string_length++;

        }



        if (new_string_length >= iLen)

                func_exit(_ERROR);



        memset(szDst, 0, iLen);

        for (c1 = szSrc, c2 = szDst; *c1 != '\0'; c1++)

        {

                if (*c1 == ' ')

                {

                        c2[0] = '%';

                        c2[1] = '2';

                        c2[2] = '0';

                        c2 += 3;

                }

                else

                {

                        *c2 = *c1;

                        c2++;

                }

        }

        *c2 = '\0';

FUNC_EXIT:

        return iReturn;

}




Thanks,

Bruce

Reply via email to