XMLHTTP solution for Win95 + vc6 + ie4 + msxml3

Source: Internet
Author: User

First, in Win95 + vc6 + ie4 + msxml3, XMLHTTP using msxml3 will encounter an error when it is open (an exception is thrown, The Exception Code is efail, and the exception description is blank ), I personally think it is a problem of wininet and urlmon (I did not confirm it in depth, I wanted to install ie5/5.5 and try again, but this version is too old to find the installation package, only the so-called green version can be found ).

Since XMLHTTP of msxml3 cannot be used, you have to write it yourself using cinternetsession:

Void send (joytech: msxml3: ixmldomdocument documentsend, const cstring & URL, const cstring & soapaction, joytech: msxml3: ixmldomdocument & documentrecv) {static lpctstr header = _ T ("accept: */* \ r \ n \ accept-language: ZH-CN \ r \ n \ x-requested-: twenxmlhttprequest \ r \ n \ Content-Type: text/XML; charset = UTF-8 \ r \ n \ UA-CPU: x86 \ r \ n \ accept-encoding: gzip, deflate \ r \ n \ soapaction :");

Cstring strheader = header + soapaction + _ T ("\ r \ n"); DWORD dwservicetype; cstring strserver, strobject; internet_port nport = 80;

// Afxparseurl of vc6 does not support internet_service_https if (! Afxparseurl (URL, dwservicetype, strserver, strobject, nport) | (dwservicetype! = Internet_service_http) throw new joytech: exception: cjoytechexception (_ T ("Protocol Error in URL! "));

Cstring xml = documentsend. getxml (); cinternetsession session; chttpconnection * pconnection = session. gethttpconnection (strserver, nport); chttpfile * pfile = pconnection-> openrequest (chttpconnection: http_verb_post, strobject); pfile-> sendrequest (strheader, (lpvoid) (lpctstr) XML, XML. getlength () * sizeof (tchar); DWORD dwret; pfile-> queryinfostatuscode (dwret); If (dwret! = Http_status_ OK) throw new joytech: exception: cjoytechexception (_ T ("XMLHTTP status error! "));

Cstring strxml; int nsize = pfile-> getlength (); {cstring strread; while (pfile-> readstring (strread) strxml + = strread;} pfile-> close (); delete pfile; pconnection-> close (); Delete pconnection; Session. close ();

Joytech: msxml3: createxmldocument (documentrecv); documentrecv. loadxml (joytech: stringconvert: joytech_utf82t (lpcstr) strxml); // although strxml is of the cstring type, however, the internal data is actually utf8 (dependent on the XML serialization code of the WebService server) format, so you need to manually convert it to the lpctstr format}

Note the following two points:

1. If you want to support HTTPS and other protocols, you must write the URL resolution function by yourself, because the URL resolution function afxparseurl of vc6 only supports internet_service_url, internet_service_ftp, internet_service_gopher, and internet_service_http.

2. although the data returned from the server is obtained using pfile-> readstring in the Code and is of the cstring type, it cannot be simply processed as a cstring. Be sure to note that, the returned XML text is encoded, generally utf8! In addition, you must note that the API function multibytetowidechar/widechartomultibyte IN Win95 does not support utf8, so you need to write it yourself.

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.