Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HTTP REQUEST ERROR HANDLING

JINESH GANDHI

IS-IT--Management
May 8, 2022
16
IN
HOW TO CHECK WHETHER THE SERVER REQUEST IS EXIST OR NOT.

loRequest = loHTTP.open('POST',"https://www.atariarprise.com/acdataup.php")
loHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
loHTTP.Send(lcformdata)

I would like to chec lohttp.open is exist or not? while using lotthp.send i found error OLE IDispatch exception code 0
 
HOW TO CHECK WHETHER THE SERVER REQUEST IS EXIST OR NOT.

loRequest = loHTTP.open('POST',"https://www.atariarprise.com/acdataup.php")
loHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
loHTTP.Send(lcformdata)

I would like to chec lohttp.open is exist or not? while using lotthp.send i found error OLE IDispatch exception code 0
Hello,

oObject = CREATEOBJECT([WinHttp.WinHttpRequest.5.1])

WITH oObject

.Open([POST], m.url, .F.)

.SetRequestHeader("Content-type", "application/soap+xml; charset=utf-8")
.SetRequestHeader("Accept", "*/*")
.SetRequestHeader("KeepAlive", .T.)
.SetRequestHeader("AllowAutoRedirect",.F.)
.SetRequestHeader("PreAuthenticate",.T.)
.SetRequestHeader("OSCP_RESPONSE", m.token)
.SetRequestHeader("Set-Cookie", m.cookie)
.SetRequestHeader("SOAPAction", m.url_soap)
.SetRequestHeader("UserAgentString", "Visual FoxPro 9")
.SetCredentials(m.username, m.password, 0)
.SetClientCertificate(m.certif_name)
.SetTimeouts(30000, 30000, 30000, 30000)

*!* very important!!! ignore all errors
.option(4)=13056

nErr = 0 && no error

TRY
WAIT WINDOW NOWAIT "try to send..."
.Send(m.xmlDoc)

WAIT CLEAR
CATCH
WAIT CLEAR
nErr=1 && if error, the .status property gives more information
*!* Error message
ENDTRY

IF .status # 200
*!* something is wrong
*!* treat the error number
ELSE
WAIT WINDOW NOWAIT "Autentication succesfully!"
ENDIF
ENDWITH
 
It would help to post your full code, not just a snippet.

In the code you posted, there still are obvious errors. Assuming loHTTP is something like Msxml2.ServerXMLHTTP.6.0, then loHTTP.open does not return an object. The loHTTP object already is your request object.
When you call send it's readyState property will change and the reesponse from the server exists, when readyState is 4.
 
Thanks Chriss

Please find the code here with.

lcformdata=""
loHttp = CreateObject('Msxml2.ServerXMLHTTP.6.0')
v1=loHTTP.open('POST',"https://www.katariaenterprise.com/acdataup.php")
IF ISNULL(v1)
WAIT WINDOW "ax"
endif
loRequest = loHTTP.open('POST',"https://www.atariaenterprise.com/acdataup.php")
loHTTP.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
loHTTP.Send(lcformdata)
DO WHILE loHTTP.READYSTATE # 4
DOEVENTS
ENDDO

Before ready state statement the error stop the software, as per the screen shot given below i want to encounter error through code. please help me

1741263003508.png
 
Indeed, the domain atariaenterprise.com does not exist, a whois lookup tells this domain is free for registration, so it's not just a temporary server outage.

Is your question about how to catch that error? Normal ON ERROR handling would do so, in modern VFP9 you can put this into TRY...CATCH...ENDTRY, too.
Code:
lcformdata=""
loHttp = Createobject('Msxml2.ServerXMLHTTP.6.0')
Try
   loHttp.Open('POST',"https://www.atariaenterprise.com/acdataup.php")
   loHttp.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded")
   loHttp.Send(lcformdata)
   Do While loHttp.READYSTATE # 4
      DoEvents
   EndDo
   ? "Response:", loHttp.responseText
Catch To loException
   ? "VFP caught this error:"
   ? "The request failed with error message:"+loException.Message
Endtry
Please just take a very close look at your code, in one line, you have the correct URL, in the next line the wrong. The error is what you get from trying to address a non existing URL.
 
Last edited:
Looks like you got some answers, but I don't think there's a way to know what you want to know, at least in a short amount of time. If you send a request, you have to deal with the timeouts, which you can control, but that's of limited value. The vagaries of communication across the Internet means you're not going to be able to just say "hey, you out there" or "hey, do this" and get some kind of instantaneous response. Packets can get held up, servers can be busy, etc. You can lower the timeouts, but let's say you lower it to 3 seconds. In three seconds, you get no response and the server is "clearly" not available. Yet it responded in 3.5 seconds. Oops. You can say "well, it's not there in enough time to suit my purposes," I guess, but that may not be practical, either. You could try pinging to get basic info, but that's not all that different. And if you ping, see it's responding, then send the request, you may double your time for a real response. And some servers turn off pinging.

Edit for clarity: I'm speaking in general terms here. The way to know is, of course, get the docs from whatever service you're hitting and adhere to them and then "you know," but, in general terms, you don't know if the URL/service does not exist, is down, is slow, etc. You just know you didn't get a response after X seconds.
 
I only said it looks like trolling, because that's what trolling looks like. It may turn out as that, in the end, it may not.

And why complain, didn't I gave an answer, still?

In my experience with trolls the best way to get rid of them is being direct to the point. If it is a troll, he'll lose the interest of being taken serious while he's obviously not serious or even toxic. I notice that you're meaning I'm toxic, here. Well, in the aspect of being very direct, yes. But directness also comes from the error rmessage, doesn't it? So is the developer deciding to make that error message toxic? Or is it just directly pointing out what's wrong? Or is that beyond any doubt and consideration, as it's of course not personal because it was decided generally, not only towards this developer?

In the question I sense JINESH GANDHI does not see an error made, even though it is very blatantly there. And the other, even more likely interpretation is he's trolling. I mean, I could also assume things that are even less flattering. "Accusing" of trolling is at least giving it the doubt of trying to outsmart this forum by tricking it into pondering why this obviously correct code fails. There is no reason to ponder, as the error message in this case is not misleading.
 
Last edited:
Hello Everyone,

Thanks Everyone,

First of all I clear that I am not trying troll any one but I am facing the issue as shown in my details. Actual code working but the error found on my client server and I am unable to trace the same on client server, that's why i have made a sample code with wrong url to understand the problem.

Sorry if any one is hurt.

And Thank you so much to everyone.
 
The sample code you gave has two calls to open. You don't do that.

i have made a sample code with wrong url to understand the problem.
Okay, do you get the same error as reported by the client?
Actual code working but the error found on my client server
Then what is the actual code and what is the error reported? If you want to get an analysis of the actual problem, then it's best to also post the actual code. A repro sample helps, of course, but only if it is the original problem. And, well, I do see the same error, it's telling that the URL can't be reached, in short.

You don't get an error for correct URLs, but for wrong ones Msxml2.ServerXMLHTTP.6.0 reports the error you got in your screenshot -"The server name or address could not be resolved". In other instances you might get status numbers like 404 not found, but that's only coming for URLs not found on a server, a 404 indirectly means you already reached the server and the server exists, but not the specific URL. And there are further errors, like 503 internal server error, which also indirectly tells the server address at least exists, but the server has problems to respond, maybe even to any requests.

Overall there are so many different error messages and statuses you can get at, that it is asked too much to discuss all of them here, the core way to distinguish a successful request is that it finally leads not only th readyState 4, but will have status 200 "OK". Anything else is not normal and requires at least logging it to keep knowledge of problematic requests.

Okay, so what does it mean "The server name or address could not be resolved". You have to have a bit of background knowledge about how making a http request works, even though you use a class doing all the nitty gritty low level details for you. Name resolving (detrmining the actual IP address) fails in this case, which throws an actual error and not only some of the status codes you could get in a response. It's a more severe error, obviously, as the server address can't be determined, so there also is no way to get to a server response with the usual status. code and message associated.

The error comes from send, not open, by the way, and you can get this detail fro jus the same error handling that you always use for any errors, too. Besides the try...catch I demonstrated.

If you don't implement error hanlding in any way, you get such raw messageboxes that contain some technical numbers besides a message text that actually is intended for developers, not users of a software, of course. I can totally understand the confusion of a user confronted with this, if they don't even know what URL and server was requested. That's also the core reason you do error handling that at least logs errors for you to investigate and fix and maybe show them to the user or just display a generic error message to them. With try catch you can do very specific error handling of expected problems. A non working URL is surely one of those to be expected errors, even if you know all your URLs used in code are okay.

I don't see how we could help you further than demonstrating how you handle errors, if a URL from data or entered by a user causes that error, you surely need to be prepared for this to possibly happen and you can indeed recover from this, it's not a reason to exit the process you just got the feedback that the server can't be reached. It's out of your hands, usually, unless you're also the network admin that configures internet access or even worse, the maintainer of the addressed server.
 
HOW TO CHECK WHETHER THE SERVER REQUEST IS EXIST OR NOT.
Let me rephrase what I think you mean: How to check whether the server exists.

Well, one straight forward answer is that you get the error you see. In detail that error could also mean the URL name resoultion fails and the server still exists, in principle.

I indirectly hinted on whois, a whois query will tell you whether a domain name is registered at all. This bureaucratic information is closely coupled to the technical resolvability of a URL or more specific the domain part of it.

I second GTGeek88 on this aspect:
in general terms, you don't know if the URL/service does not exist, is down, is slow, etc.
In your sepcific error you know at least you can't even reach the server by everything DNS knows (or does not know, indeed). And you can't do any code to prevent this from happening, even with well known URLs. You don't first make a whois request before making the http request, you handle the results, also when they are errors.
 
Last edited:
Now I understand very well. Let me finished TRY...CATCH method as you demonstrated. If still the problem remain again I will post the detail code.
Will be back with result.

Thanks for your guidance.
Have a nice day ahead.
 

Part and Inventory Search

Sponsor

Back
Top