简体   繁体   中英

Parse HTML into web service from Classic ASP

I am trying to build a webservice where a user enters HTML and then via a web service verifies if it is valid HTML.

My example (basic only) is:

Set objXML = CreateObject("Msxml2.ServerXMLHTTP.6.0")         
Dim strEnvelope 
strEnvelope = "input=" & Server.HTMLEncode("<b>") 
Call objXML.Open("POST", "http://[DOMAIN]/WebServices/HTMLWebService.asmx/ValidateHTML", false) 
Call objXML.SetRequestHeader("Content-Type","application/x-www-form-urlencoded") 
Call objXML.Send(strEnvelope) 

Response.Write(strEnvelope & "##" & objXML.responseText & "##")

My ASPX page validates the input and then returns if it's true of false (in a string array XML). At the moment it's always returning false. After some investigation it seems that for some reason the input received by the ASMX is empty and it's to do with the HTML tagging - either it's not being HTML encoded or not accepted by the asmx script. It's returning the following:

<?xml version="1.0" encoding="utf-8"?>
<ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://tempuri.org/">
<string />
<string>false</string>
</ArrayOfString>

<string /> is where I am putting the input directly back into the returned xml string array. If I hard code "<b>" into this value, the xml returns this as "<b>" which is what I'd expect.

If I just put an input of "b" then it returns false but does give me a value of "b" in the first item of the string array - so it's definitely picking up that value.

Has anyone ever parsed html into an ASP.NET (c#) web service before or have any suggestions?

Not 100% sure, but since you specify in your request header that the contenttype is "application/x-www-form-urlencoded" it could be that you need to use URLEncode and not HTMLEncode. Thus, try using:

strEnvelope = "input=" & Server.URLEncode("<b>") 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM