Hallo, i have serious problem with this wininet function, whe i run my program on windows 7, everything works perfectly, but when i try to use it on windows XP service pack 3. Sometimes it takes for HttpSendRequst too long time to finish and i really dont know why and sometimes for the same request, it finishes almost instantly. I am loading websites with my prog.
What is the difference between Win 7 and XP in wininet? I tried allmost everything but doesnt work. For example set time out for Httpsendrequest and repeat again or set maximum internet connections for more. But nothing seemed to work and the functionality was allways the same.
Please help if you can.
m_hInternet = InternetOpenA(m_strAgentName.c_str(), INTERNET_OPEN_TYPE_PRECONFIG ,
NULL, NULL, 0);
if (!m_hInternet) {
m_strLastError = "Cannot open internet";
m_lastErrorCode = GetLastError();
return false;
}
m_hSession = InternetConnectA(m_hInternet,
m_strServerName.c_str(),
m_wPort,
m_strUserName.c_str(),
m_strPassword.c_str(),
INTERNET_SERVICE_HTTP,
INTERNET_FLAG_KEEP_CONNECTION,
0);
m_hRequest = HttpOpenRequestA(m_hSession,
this->m_strMethod.c_str(),
m_strObjectName.c_str(),
NULL,
m_strReferer != "" ? m_strReferer.c_str() : NULL,
NULL,
INTERNET_FLAG_NO_AUTO_REDIRECT | INTERNET_FLAG_KEEP_CONNECTION,
m_ReqID);
bool result = HttpSendRequestA( m_hRequest,
this->m_strAddHeaders.size() == 0 ? NULL : this->m_strAddHeaders.c_str(),
this->m_strAddHeaders.size(),
(char*)this->m_strContent.c_str(),
this->m_strContent.size());
Do you check that request is completed successfully? There should be some response code with text. Otherwise your fast requests could be caused by abnormal termination.
If this is a complete code sample I’d suggest adding HttpEndRequest.
I have encountered this problem a couple of times when the request doesnt finish at all.
The only solution i have found to this is giving the program enough time between each request.
So you can use a buffer to store and add all the data and every X time you send it trough the request!
Related
I have a C++ written Windows service, and on startup, if the SERVICE_STATUS stays in SERVICE_START_PENDING too long, I end up with this error :
Error 1053: The service did not respond to the start or control request in a timely fashion
This happens when keeping the progress bar dialog opened. It does not affect the service startup itself. The service will continue in SERVICE_START_PENDING until the work is completed and I set SERVICE_RUNNING.
The Windows documentation on dwWaitHint here :
https://msdn.microsoft.com/en-us/library/windows/desktop/ms685996(v=vs.85).aspx
states that the service must call SetServiceStatus with an incremented dwCheckPoint before the dwWaitHint time elapses.
So for example, I set dwWaitHint to 5 minutes, and call SetServiceStatus every 10 seconds with an incremented dwCheckPoint but I still get the 1053 error after 5 minutes. In other words, the SetServiceStatus calls don't seem to do anything. (and these calls are NOT failing, I checked).
By doing the above, can't the service startup time take longer than dwWaitHint ???
UPDATE: I can reproduce with Microsoft's service sample code. Here's a snippet.
{
gSvcStatus.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
gSvcStatus.dwServiceSpecificExitCode = 0;
// Report initial status to the SCM
ReportSvcStatus( SERVICE_START_PENDING, NO_ERROR, 300000 );
int limit = 6; // 6 minutes total
while(limit--)
{
Sleep(60000); // sleep 1 min
ReportSvcStatus( SERVICE_START_PENDING, NO_ERROR, 300000 ); // 5 minute dwWaitHint
}
// We've completed startup, report RUNNING to SCM
ReportSvcStatus( SERVICE_RUNNING, NO_ERROR, 0 );
}
VOID ReportSvcStatus( DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
{
static DWORD dwCheckPoint = 1;
// Fill in the SERVICE_STATUS structure.
gSvcStatus.dwCurrentState = dwCurrentState;
gSvcStatus.dwWin32ExitCode = dwWin32ExitCode;
gSvcStatus.dwWaitHint = dwWaitHint;
if (dwCurrentState == SERVICE_START_PENDING)
gSvcStatus.dwControlsAccepted = 0;
else gSvcStatus.dwControlsAccepted = SERVICE_ACCEPT_STOP;
if ( (dwCurrentState == SERVICE_RUNNING) ||
(dwCurrentState == SERVICE_STOPPED) )
gSvcStatus.dwCheckPoint = 0;
else gSvcStatus.dwCheckPoint = dwCheckPoint++;
// Report the status of the service to the SCM.
SetServiceStatus( gSvcStatusHandle, &gSvcStatus );
}
You are sure you are treating dwWaitHint as millseconds and not seconds? (i.e. your dwWaitHint is 300000?)
My experience is that the docs are right on this point, that the wait hint only applies to the next SetServiceStatus call.
Although I would also say a 5min service start time is excessive even if it actually takes that long to load or check data. Mostly I say that because the service control interface is stuck that entire time. SQLServer for example does a fairly quick service start even after a system crash that requires hours of validation.
Well, there are definitely limitations to the Microsoft Management Console (MMC) Services snap-in, specifically this dialog here :
See this link here from MS :
https://support.microsoft.com/en-ca/help/307806/the-services-snap-in-times-out-with-error-1053
When any control operation is initiated, the Services snap-in displays a progress dialog box with the title "Service Control". If a service requires a significant amount of time to process an operation, the progress bar will slowly increment as the Services snap-in waits for the operation to finish. After 125 seconds, the progress bar will be full and the Services snap-in will display the error 1053 (ERROR_SERVICE_REQUEST_TIMEOUT) message. The service process itself will continue its operation as usual even after the error message has appeared.
But, the somewhat good news is I've proven this 125 seconds statement to be false, at least on Windows 10 (haven't tried other Windows versions). As stated in my question, when setting the SERVICE_START_PENDING, you can set the dwWaitHint to something higher, and the progress bar will respect that. But, you only have 1 chance at this, if you then update SERVICE_START_PENDING by calling SetServiceStatus with a higher dwWaitHint, it will not affect the progress bar dialog.
The only downside to setting dwWaitHint really high is that the progress bar will slow down, and when you set the SERVICE_RUNNING status, the progress bar might just be half way. But not a big deal, just aesthetic.
I am working on an application where there are read only screens.
To test whether the data is being fetched on screen load, i want to set some wait time till the screen is ready.
I am using python to record the actions. Is there a way to check the static text on the screen and set the time ?
You can simply use
snooze(time in s).
Example:
snooze(5)
If you want to wait for a certain object, use
waitForObject(":symbolic_name")
Example:
type(waitForObject(":Welcome.Button"), )
The problem is more complicated if your objects are created dynamically. As my app does. In this case, you should create a while function that waits until the object exists. Here, maybe this code helps you:
def whileObjectIsFalse(objectID):
# objectID = be the symbolic name of your object.
counter = 300
objectState = object.exists(objectID)
while objectState == False:
objectState = object.exists(objectID)
snooze(0.1)
counter -= 1
if counter == 0:
return False
snooze(0.2)
In my case, even if I use snooze(), doesn't work all the time, because in some cases i need to wait 5 seconds, in other 8 or just 2. So, presume that your object is not created and tests this for 30 seconds.
If your object is not created until then, then the code exits with False, and you can tests this to stop script execution.
If you're using python, you can use time.sleep() as well
Any body have any luck with ShellTileSchedule? I have followed the Microsoft example and still have gotten no where.
"How to: Update Your Tile Without Push Notifications for Windows Phone"
Has any one seen a complete example that works on a device or emulator?
Yes...I started with the sample at http://channel9.msdn.com/learn/courses/WP7TrainingKit/WP7Silverlight/UsingPushNotificationsLab/Exercise-2-Introduction-to-the-Toast-and-Tile-Notifications-for-Alerts/
and skipped immediately down to "Task 3 – Processing Scheduled Tile Notifications on the Phone." After that I had to wait about 1 hour, leaving the emulator running on my desktop (1 hour is the minimum update interval, indicated as such for "performance considerations."
_shellTileSchedule = new ShellTileSchedule
{
Recurrence = UpdateRecurrence.Interval,
Interval = UpdateInterval.EveryHour,
StartTime = DateTime.Now - TimeSpan.FromMinutes(59),
RemoteImageUri = new Uri(#"http://cdn3.afterdawn.fi/news/small/windows-phone-7-series.png")
};
Note that setting the StartTime to DateTime.Now - 59 minutes did nothing. It still waited a full hour for its first update. I could not find any mechanism to perform "go to this URI and Update yourself NOW!", other than calling out to a web service that tickles a Tile Notification.
as #avidgator said, you'll have to wait an hour.
i have written a tutorial on how to update the tile instantly here:
http://www.diaryofaninja.com/blog/2011/04/03/windows-phone-7-live-tile-schedules-ndash-executing-instant-live-tile-updates
basically it involves opening a push/toast update channel and then getting the phone to send "itself" a live tile update request. this will trigger the phone to go and get the tile "right now"
hope this helps
Are the channels necessary for this kind of update?
Is there a full code example of what has to be done to create an app that just updates its tile?
BTW: How about setting the Recurrence to UpdateRecurrence.Onetime and the StartTime to Now + 20 seconds for testing purposes?
I just got an tile update after an hour without channels and so on. So that answered my first question. But having to wait an hour while trying to develop an app is... unsatisfying.
It is easy. Just use the following code when you setup ShellTileSchedule.
ShellTile applicationTile = ShellTile.ActiveTiles.First();
applicationTile.Update(
new StandardTileData {
BackgroundImage = new Uri("www.ash.com/logo.jpg"),
Title = ""
});
I am using vbscript .vbs in windows scheduler.
Sample code:
objWinHttp.Open "POST", http://bla.com/blabla.asp, false
objWinHttp.Send
CallHTTP= objWinHttp.ResponseText
strRESP= CallHTTP(strURL)
WScript.Echo "after doInstallNewSite: " & strRESP
Problem: blabla.asp is handling a task that need around 1-2 minute to complete.
It should return 'success' when the task completed.
But it return a empty result to the server vbs. (shorter than the normal time to complete the thing. I then go to check whether the task is completed, the answer is yes too.
I found this to happen when the task need longer time to complete.
Is this the weakness of vbs?
Help!!!
You can specify timeouts for the winhttp component:
objWinHttp.SetTimeouts 5000, 10000, 10000, 10000
It takes 4 parameters: ResolveTimeout, ConnectTimeout, SendTimeout, and ReceiveTimeout. All 4 are required and are expressed in milliseconds (1000 = 1 second). The defaults are:
ResolveTimeout: zero (no time out)
ConnectTimeout: 60,000 (one minute)
SendTimeout: 30,000 (30 secs.)
ReceiveTimeout: 30,000 (30 secs.)
So I suggest increasing the ReceiveTimeout
What is objHTTP specifically?
Looking at the target server's log, was the request received?
I can't find this in server log.
objWinHTTP is a standard protocol to send call and wait for response.
I did try using PHP and curl to do the whole process, but failed. Reason: PHP is part of the component in windows server. When come to global privilege and file folder moving, it is controlled by windows server. So I give up, and use vbs.
objWinHTTP is something act like curl in PHP.
sounds to me like the request to is taking too long to complete and the server is timing out. I believe the default timeout for asp scripts is 90 seconds so you may need to adjust this value in IIS or in your script so that the server will wait longer before timing out.
From http://msdn.microsoft.com/en-us/library/ms525225.aspx:
The AspScriptTimeout property
specifies (in seconds) the default
length of time that ASP pages allow a
script to run before terminating the
script and writing an event to the
Windows Event Log. ASP script can
override this value by using the
ScriptTimeout property of the ASP
built-in Session object. The
ScriptTimeout property allows your ASP
application to set a higher script
timeout value. For example, you can
use this setting to adjust the timeout
once a particular user establishes a
valid session by logging in or
ordering a product.
My program puts a file into a remote host using HTTP. For some unavoidable
reasons, the remote hosts needs some time to acknowledge the final packet of
the data transmission. More time than the default timeout, which according
to my experience is around 30 seconds.
Therefore I wanted to increase the timeout to 5 minutes, using this code:
DWORD dwTimeout= 300000; // 5 minutes
pFtpConnection->SetOption( // KB176420: this has no effect on some
INTERNET_OPTION_SEND_TIMEOUT, dwTimeout); // old versions of IE.
pFtpConnection->SetOption(
INTERNET_OPTION_RECEIVE_TIMEOUT, dwTimeout);
pFtpConnection->SetOption( // NB: Docs say these 2 are not implemented.
INTERNET_OPTION_DATA_SEND_TIMEOUT, dwTimeout);
pFtpConnection->SetOption( // our own tests show that they are!
INTERNET_OPTION_DATA_RECEIVE_TIMEOUT, dwTimeout);
This is MFC code which boils down to calling
InternetOption(hConnection, INTERNET_XXX, &dwTimeout, sizeof(dwTimeout))
The problem is that this code apparently fails to modify the timeout on a
non negligeable proportion of computers where the program is used.
How can I reliably set the data connection timeout?
TIA,
Serge Wautier.
It looks like this WinInet isue can'tbe solved reliably.
I eventually switched from WinInet to Ultimate TCP/IP.