我的桌面应用程序是HTTP将数据发布到我的Apache服务器(与我的PHP脚本交互)。我发布了大量数据(大小为800kb的文件内容)。
当我发送HTTP post请求时,它会因以下Windows错误超时:
ERROR_INTERNET_TIMEOUT请求已超时
但是如果我发送较小的文件,那么一切都很好,我的PHP脚本处理发布请求。可能是什么原因以及如何解决这个问题?
我的网站是WordPress,我更改了我的php.ini
,php5.ini
和.user.ini
,所有人都有以下文字,但大文件仍然无效。
file_uploads = On
post_max_size = 128M
upload_max_filesize = 128M
修改:使用phpinfo();
进行检查后(max_execution_time应该在结尾处有一个S(几秒钟?):
C ++代码:
TCHAR hdrs[] = _T("Content-Type: application/x-www-form-urlencoded");
LPSTR accept[2] = { "*/*", NULL };
HINTERNET hConnect = NULL, hSession = NULL, hRequest = NULL;
DWORD len = postData.length() * 2;
tstring formattedPostData(len, ' ');
InternetCanonicalizeUrl(postData.c_str(), &formattedPostData[0], &len, ICU_BROWSER_MODE);
std::replace(formattedPostData.begin(), formattedPostData.end(), '=', '~');
tstring authData = _T("usage=") + formattedPostData + _T("&auth=") + authToken;
hSession = InternetOpen(_T("uploader"), INTERNET_OPEN_TYPE_PRECONFIG, NULL, NULL, 0);
if (!hSession) {
output(_T("InternetOpen failed: %s\n"), getLastErrorAsString().c_str());
res = S_UNDEFINED_ERROR.state;
goto Cleanup;
}
hConnect = InternetConnect(hSession, domain.c_str(),
INTERNET_DEFAULT_HTTP_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 1);
if (!hConnect) {
output(_T("InternetConnect failed: %s\n"), getLastErrorAsString().c_str());
res = S_UNDEFINED_ERROR.state;
goto Cleanup;
}
hRequest = HttpOpenRequest(hConnect, _T("POST"),
domainScript.c_str(), NULL, NULL, (LPCWSTR*)&accept, INTERNET_FLAG_NO_CACHE_WRITE, 1);
if (!hRequest) {
output(_T("HttpOpenRequest failed: %s\n"), getLastErrorAsString().c_str());
res = S_UNDEFINED_ERROR.state;
goto Cleanup;
}
// Error occurs here
output(_T("Post: %s\n"), authData.c_str());
if (!HttpSendRequest(hRequest, hdrs, -1, (LPVOID)authData.c_str(), authData.size() * sizeof(TCHAR))) {
// Error is 12002: timeout
output(_T("HttpSendRequest failed: %d.\n"), GetLastError());
res = S_UNDEFINED_ERROR.state;
char responseText[1024];
DWORD responseTextSize = sizeof(responseText);
output(_T("Res: %d\n"), HttpQueryInfo(hRequest, HTTP_QUERY_RAW_HEADERS_CRLF, &responseText, &responseTextSize, NULL));
output(_T("Response: %s\n"), responseText);
goto Cleanup;
}
答案 0 :(得分:1)