Jump to content
Juvigy

winhttp post call fails from time to time

Recommended Posts

Juvigy

Hi Guys,

I am using winhttp to make calls to the ebay api. I dont know why, but sometimes the calls fail with : "The requested action with this object has failed.:" on the $oHTTP.Send line. Any idea why?

This is the code i use:

$oHTTP = ObjCreate("winhttp.winhttprequest.5.1")
    $oHTTP.Open("POST","https://api.ebay.com/ws/api.dll")
    $oHTTP.SetRequestHeader("X-EBAY-API-COMPATIBILITY-LEVEL", "391")
;~  $oHTTP.SetRequestHeader("X-EBAY-API-DEV-NAME", "not used")
;~  $oHTTP.SetRequestHeader("X-EBAY-API-APP-NAME", "not used")
;~  $oHTTP.SetRequestHeader("X-EBAY-API-CERT-NAME", "not used")
    $oHTTP.SetRequestHeader("X-EBAY-API-CALL-NAME", "GetCategories")
    $oHTTP.SetRequestHeader("X-EBAY-API-SITEID", "3")
    $oHTTP.SetRequestHeader("Content-Type", "text/xml")
    $oHTTP.Send("<?xml version='1.0' encoding='utf-8'?><GetCategoriesRequest xmlns=""urn:ebay:apis:eBLBaseComponents""><RequesterCredentials><eBayAuthToken>" & $auth_token & "</eBayAuthToken></RequesterCredentials><CategorySiteID>" & $CategorySiteID & "</CategorySiteID><DetailLevel>ReturnAll</DetailLevel><LevelLimit>" & $max_level & "</LevelLimit></GetCategoriesRequest>")
    $HTMLSource = $oHTTP.Responsetext
    Return $HTMLSourc

 

Share this post


Link to post
Share on other sites
Danyfirex

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

I've seen the same.  to get around this, I do asynchronus requests.  i have not yet seen an error from doing that which a com error handler can't catch, allowing the script to proceed.

https://msdn.microsoft.com/en-us/library/windows/desktop/aa384064(v=vs.85).aspx

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Juvigy

Thank you guys. Seems that the asynchronous thing works.  

Share this post


Link to post
Share on other sites
Juvigy
Posted (edited)

Seems i spoke too soon. It continues to fail. Now it fails with the same error but on the $oHTTP.WaitForResponse !

Here is the error handler output:

err.description is:     An error occurred in the secure channel support

err.windescription: Exception occurred.

err.number is:  80020009
err.lastdllerror is:    0
err.scriptline is:  92
err.source is:  WinHttp.WinHttpRequest
err.helpfile is:    
err.helpcontext is:     0
We intercepted a COM Error !

err.description is:     The data necessary to complete this operation is not yet available.

err.windescription: Exception occurred.

err.number is:  80020009
err.lastdllerror is:    0
err.scriptline is:  93
err.source is:  WinHttp.WinHttpRequest
err.helpfile is:    
err.helpcontext is:     0

Output has 2 errors , first is on     $oHTTP.WaitForResponse(100), second one is on $HTMLSource = $oHTTP.Responsetext

Edited by Juvigy
added error msg

Share this post


Link to post
Share on other sites
jdelaney
Posted (edited)

But your script was able to proceed, right?  I only really interact with test servers, so expect failures.  as long as I don't have to constantly restart my script, I'm happy.  example.   made a simple gui app that allows me to configure and send soap requests.   if no response, I can easily click the send button again.

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites
Juvigy

Yes, it doesnt crash because of the error handler. So i should put it in a loop and do it until i receive a response?

Share this post


Link to post
Share on other sites
jdelaney

That can work.   you might need to recreate the winhttp object each time.   i suggest putting in max retry, and exit if the response is populated.


IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×