关于WINHTTP

yzsyzx 2003-04-25 01:11:06
MSDN中有这样的代码?请问是不是实现从vc程序中提交http请求,然后可以得到XML结果,那么asp如何返回XML?


void XMLHttpRequestSample()
{
IXMLHTTPRequestPtr pIXMLHTTPRequest = NULL;
BSTR bstrString = NULL;
HRESULT hr;

try {
hr=pIXMLHTTPRequest.CreateInstance("Msxml2.XMLHTTP.4.0");
SUCCEEDED(hr) ? 0 : throw hr;

hr=pIXMLHTTPRequest->open("GET", "http://XMLSampleServer/CatalogServer.asp
SUCCEEDED(hr) ? 0 : throw hr;

hr=pIXMLHTTPRequest->send();
SUCCEEDED(hr) ? 0 : throw hr;

bstrString=pIXMLHTTPRequest->responseText;

MessageBox(NULL, _bstr_t(bstrString), _T("Results"), MB_OK);

if(bstrString)
{
::SysFreeString(bstrString);
bstrString = NULL;
}

} catch (...) {
MessageBox(NULL, _T("Exception occurred"), _T("Error"), MB_OK);

if(bstrString)
::SysFreeString(bstrString);
}

}
...全文
203 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
microran2000 2003-09-09
  • 打赏
  • 举报
回复
下面是MSDN中的英文说明,鉴于时间关系,我就不再给你翻译或者解释了。
Provides methods and properties that enable you to establish an HTTP connection between files or objects on different Web servers.

The ServerXMLHTTP object offers functionality similar to that of the XMLHTTP object. Unlike XMLHTTP, however, the ServerXMLHTTP object does not rely on the WinInet control for HTTP access to remote XML documents. ServerXMLHTTP uses a new HTTP client stack. Designed for server applications, this server-safe subset of WinInet offers the following advantages:

Reliability—The HTTP client stack offers longer uptimes. WinInet features that are not critical for server applications, such as URL caching, auto-discovery of proxy servers, HTTP/1.1 chunking, offline support, and support for Gopher and FTP protocols are not included in the new HTTP subset.
Security—The HTTP client stack does not allow a user-specific state to be shared with another user's session. ServerXMLHTTP does not provide support for certificates.
Note For more information about the limitations of the WinInet control, see WinInet Limits Connections Per Server.
Usage
The ServerXMLHTTP object is commonly used to:

Receive XML documents from an Active Server Pages (ASP) page on a local or remote Web server (HTTP GET).
Post XML documents to an ASP page on a local or remote Web server (HTTP POST).
Post and receive response XML documents from an ASP page (HTTP POST).
You can use the ServerXMLHTTP object either indirectly using the setProperty method of DOMDocument or directly using the ServerXMLHTTP object itself. For examples of these two approaches, as well as examples of how to use the ServerXMLHTTP security options and how to use ServerXMLHTTP in a multitiered environment, see IServerXMLHTTPRequest/ServerXMLHTTP Examples.

Remarks
The ServerXMLHTTP open method makes the connection between servers and the send method sends the request.

You can read the response using one of the four following properties: responseBody, responseStream, responseText, and responseXML.

With ServerXMLHTTP, the usual sequence is to call open, set any custom header information through setRequestHeader, call send, and then check one of the four response properties.

For example, an ASP, Microsoft® Visual Basic®, or C++ component on a server computer can send an HTTP request to another server and then receive the response as a stream or XML document object. The response can then be fed to downstream clients, saved to a file on the server, or combined with other XML data (potentially collected from other Web servers).

ServerXMLHTTP offers additional benefits for transporting XML data:

ServerXMLHTTP maintains state, so transactional XML data can be used in business applications that require real-time responses.
ServerXMLHTTP allows you to serve the response object as a stream or Document Object Model (DOM) object. As a stream, this offers considerable performance benefits when moving data through the HTTP protocol.
ServerXMLHTTP offers some backward compatibility with XMLHTTP. Source code (JScript, Visual Basic Scripting Edition, Visual Basic, or C++) that uses the XMLHTTP component can be easily modified to use the new ServerXMLHTTP component.

The maximum number of instances that can exist simultaneously within a single process is 5,460. A similar limitation applies to the XMLHTTP component. However, other factors, such as available memory, CPU processing capacity, or available socket connections can further limit the number of instances that can be active simultaneously. Partition the server application into multiple processes if this limit becomes a bottleneck.


The IServerXMLHTTPRequest interface inherits from IXMLHTTPRequest and extends it
with the following four new methods: getOption, setOption, waitForResponse, and setTimeouts.

Requirements
Supported platforms include Microsoft Windows® 2000, or Microsoft Windows NT® 4.0 with Microsoft Internet Explorer 5.01 (or later) installed. ServerXMLHTTP fails on other platforms, such as Microsoft Windows 95 or Microsoft Windows 98.


microran2000 2003-09-09
  • 打赏
  • 举报
回复
这是MSXML组件提供的一个IXMLHttp接口,这个接口是一个COM接口,所以它适用于所有支持COM的语言环境包括ASP。不过根据微软提供文档,在ASP最好使用IServerXMLHTTPRequest/ServerXMLHTTP
<%@language=JScript%>
<%
var objSrvHTTP;
objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP");
objSrvHTTP.open ("GET","http://someotherserver/respond.asp", false);
objSrvHTTP.send ();
Response.ContentType = "text/xml";
Response.Write (objSrvHTTP.responseXML.xml);
%>
<%@language=JScript%>
<%
var objSrvHTTP;
var objXMLDocument;
objSrvHTTP = Server.CreateObject ("MSXML2.ServerXMLHTTP");
objXMLDocument = Server.CreateObject ("MSXML2.DOMDocument");

objXMLDocument.async= false;
objXMLDocument.resolveExternals = false;
objXMLDocument.loadXML ("<msg><id>1</id></msg>");

objSrvHTTP.open ("POST","http://someotherserver/respond.asp",false);
objSrvHTTP.send (objXMLDocument);
Response.ContentType = "text/xml";
Response.Write (objSrvHTTP.responseXML.xml);
%>
<%@language=Jscript%>
<%
var objSrvHTTP;
var objXMLSend;
var objXMLReceive;
objSrvHTTP = Server.CreateObject("MSXML2.ServerXMLHTTP");
objXMLSend = Server.CreateObject("MSXML2.DOMDocument");
objXMLReceive = Server.CreateObject("MSXML2.DOMDocument");

objXMLSend.async = false;
objXMLSend.resolveExternals = false;
objXMLSend.loadXML ("<msg><id>2</id></msg>");

objSrvHTTP.open ("POST","http://someotherserver/respond.asp",false);
objSrvHTTP.send (objXMLSend);
objXMLReceive = objSrvHTTP.responseXML;
Response.ContentType = "text/xml";
Response.Write (objXMLReceive.xml);
%>

tfp 2003-09-09
  • 打赏
  • 举报
回复
!!

QQ 63047710

i want to know about this ,
loopyifly 2003-04-25
  • 打赏
  • 举报
回复
up

3,055

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC HTML/XML
社区管理员
  • HTML/XML社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧