Reputation: 31878
I'm trying to get a response from a ASP.NET webservice without using the get parameters. I have the following code.
strBarcode = "ABC123
strURL ="http://serverName/BarcodeGenerator.asmx"
Set xmlReq = Server.CreateObject("Msxml2.DOMDocument.3.0")
Set xmlResp = Server.CreateObject("Msxml2.DOMDocument.3.0")
Set httpReq = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlReq.async = false
strXML = CStr(CreateRequest(strBarcode ))
xmlReq.loadXML(CStr(strXML))
//Open, async
httpReq.open "POST", CStr(strURL), true
httpReq.setRequestHeader "Host", "serverName"
httpReq.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
httpReq.setRequestHeader "SOAPAction", "http://tempuri.org/GetBarcode"
httpReq.send(xmlReq)
strDone = "0"
bTimeout = false
dStart = Now()
dEnd = Now()
lCounter = 0
lCounterPrev = -1
intStatus = 0
Do while intStatus <> 4 and (Not bTimeout)
dEnd = Now()
lCounter = DateDiff("s",dStart,dEnd)
if lCounter > 30 then bTimeout = True
%>. <%
'Wait a second
httpReq.waitForResponse 1000
intStatus = httpReq.readyState
Loop
If httpReq.readyState = 4 Then
bTimeout = false
Set xmlResp = httpReq.responseXML
%>
Status: <%=httpReq.statusText%><BR>
Response: <%=httpReq.responseText%> <BR><BR>
<%
Set nodes = xmlResp.getElementsByTagName("GetBarcodeResult")
If (nodes is nothing) THen
%>Nodes is NULL<BR><%
Else
%>Number of Nodes: <%=nodes.length%><%
End IF
Set node = nodes(0)
url = node.nodeValue
End If
The status is
Status: Bad Request
and the response is
Response: Bad Request (Invalid Hostname)
What am I doing wrong?
Upvotes: 2
Views: 3733
Reputation: 31878
This article (now via web.archive.org for posterity) explains it best, but basically, due to IIS configuration the server was unable to locate itself (the classic-asp and webservice were hosted on the same server). There are no problems with the code.
Upvotes: 1
Reputation: 189555
Your code is attempting to set the Host header itself. You should not be doing this.
ServerXMLHTTP will do this for you drawing the host string from the URL provided. By attempting to add it yourself you are corrupting an important criteria for the HTTP protocol. Host is the most fundemental header in the 1.1 protocol, it is the only header that must be present in a 1.1 request.
I'm not sure why you are using an asynchronous request and WaitForResponse just to detect a timeout. Why not use the setTimeouts method and a synchronous request?
Upvotes: 1