Return web service

SomeITGuy

New member
Local time
Today, 06:13
Joined
May 10, 2012
Messages
7
In its simplest form I am trying to return the name of the local authority of an area when a postcode is entered into a box.

I have a button and at present would only really need it outputting to a msgbox. The API for the website is below. I cant post links as I am new so have put spaces instead of dots of slashes.

neighbourhood statistics gov uk HTMLDocs downloads Technical_Implementation_Guide_v2.pdf

At the moment the code is basic, but not working at all. It returns the XML but not with any info which it has looked up. Any help would be much appreciated.

Private Sub Command329_Click()
Dim XMLHttp As New MSXML2.XMLHttp
XMLHttp.Open "POST", "neighbourhood statistics gov uk NDE2 Disco GetLevelTypes?", False
XMLHttp.send "NG7 2NR" ' Send in the postalcode
MsgBox XMLHttp.responseText
MsgBox XMLHttp.responseBody
MsgBox XMLHttp.statusText
End Sub
 
There is stuff missing in your code. Because the response is not instantaneous, and you need to wait with the next line of code until the thing has finished receiving the response. Isn't that in any code samples you took this code from?

I could dig some stuff up - but first check your docs and post back. Put some delaying code after the .send and see if that helps temporarily.
 
The original code was quite simple

Private Sub Command329_Click()
Dim XMLHttp As New MSXML2.XMLHttp
XMLHttp.Open "POST", "URL Here", False
XMLHttp.send "thing to send"
MsgBox XMLHttp.responseText
End Sub

What do you mean by delaying code? Never needed any before now as usually want everything to happen as fast as possible.
 
Put some delaying code -a loop that loops 1000000 times for example. What you want is not applicable, because it takes time to get a response from a web server, but your code continues before letting the server respond. I think. Unless I got confused with InternetExplorer. Try it - it cannot hurt.

Update:
I had a look in my stuff, and the False (async flag) makes it synchronous. So no delay need be coded, sorry.
 
Last edited:
XMLHTTP.STATUS = 200 , to be checked before you check the .reponseText, means it got the data OK - anything else, means something else. Google it.
 

Users who are viewing this thread

Back
Top Bottom