XMLHTTP Development Web Client

Source: Internet
Author: User
Tags format error code string version client
web|xml| Client

Keywords: xmlhttp,xml,web client, c#,asp

All knowledge is not the latest knowledge point, the key is to achieve their own design purposes.

At some point, we may need clients to do something to simplify complex scripting, such as encryption and so on.

Regardless of the client, first we should determine the protocol we are complying with, or how to set or get my data. Here, our server-side is IIS5 ASP program, so we first follow the HTTP protocol, and then transfer XML on the HTTP protocol. Using XML because it's easier to unify our data formats, the idea of XML is why we don't use it.

Just XMLHTTP, is a convenient class for transferring XML based on HTTP.

First, briefly describe the two functions of XMLHTTP:

Open (Bstrmethod, bstrURL, Varasync, Bstruser, Bstrpassword)

Open the connection specified by Bstrmethod (such as post,get, etc.) by using the HTTP method specified by the bstrURL, where Varasync is asynchronous, Bstruser, and the user and password are required to access bstrpassword.

Send (Varbody)

The data sent, or should be said to be submitted.

You can view the related MSXML SDK in detail.

The following uses C # to implement the transfer of XML, assuming that the feedback XML format is "<response><error id=\" 0\ "> Success </ERROR></RESPONSE>"

Private MSXML2.   Domdocument40class Zxml; Processing Server Feedback Results
private int zlasterrorcode;

private string zlasterrordescription;

Private Const int oksuccess=0;

The things that start with err are constants.

private int Executecmd (string scmd, String method, String ext)

{

The code omitted from the SURL is computed according to the scmd.

......

Try
{
MessageBox.Show (sURL);
Zxmlhttp.open (method, sURL, False, "", "");
Zxmlhttp.send (EXT);
}
Finally
{
Detection settings The last error code and description

Check the status of Zxmlhttp
if (zxmlhttp.status/100 ==2)//200, 201, 202, 203, 204, 205, 206
{
Success
MessageBox.Show (Zxmlhttp.responsetext);
Zxml.loadxml (Zxmlhttp.responsetext);

if (zxml.parseerror.errorcode!=0)
{
Zlasterrorcode = Errprotocol;
Zlasterrordescription = "Error parsing server feedback results, protocol version may not be correct";
Zlasterrordescription = ZXml.parseError.reason; The bank should be used only for debugging, and should use the previous line when publishing
MessageBox.Show (Zxmlhttp.responsetext);
}
Else
{
s = Getxmlnodevalue (Zxml, "/response/error/@ID ");

if (s.length==0)
{
Zlasterrorcode = oksuccess;
}
Else
{
Try
{
Zlasterrorcode = Convert.ToInt32 (s);
}
Catch
{
Zlasterrorcode = Errunknown;
}
}

Zlasterrordescription = Getxmlnodevalue (Zxml, "/response/error");
if (zlasterrordescription.length==0)
{
if (zlasterrorcode==oksuccess)
{
Zlasterrordescription = "Successful Execution";
}
Else
{
Zlasterrordescription = "Unknown error message";
}
}
}
}
Else
{
Server error
Zlasterrorcode = Errservice;
Zlasterrordescription = Zxmlhttp.statustext;
}
}

return zlasterrorcode;
}

Then the server-side test.asp

<% Language=vbscript%>

<%

Dim oXML

Set oXML = Server.CreateObject ("msxml2.domdocument.4.0")
Oxml.async = False
Oxml.resolveexternals = False

Oxml.load Request

' Then process the submitted XML data

Set oXML = Nothing

' Finally, feedback processing results
Response.ContentType = "Text/xml" Because the feedback is XML indispensable!!
response.charset= "gb2312" ' feedback content encoding, indispensable!! Otherwise, illegal characters cannot be resolved by the client Response.Write "<?xml version=" "1.0" "encoding=" "gb2312" "?>" & VbCrlf
Response.Write "<RESPONSE><VERSION>1.0.0.0</VERSION><TEST> Chinese people Long live </test></ Response> "& VbCrlf
%>

The last thing to say is the transfer of XML data format, you can say that is your own definition of the agreement, the above is just a trigger. Try, everything in your own. "& Vbcrlfresponse.write" 1.0.0.0 the Chinese People Long Live "& Vbcrlf-->" & Vbcrlfresponse.write " Long live the 1.0.0.0 Chinese People" & vbcrlf--> "& Vbcrlfresponse.write " 1.0.0.0 The Chinese People Long Live "& Vbcrlf-->" & Vbcrlfresponse.write " 1.0.0.0 The Chinese People Long Live "& vbcrlf-->



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.