delphi中Msxml2.XMLHTTP调用(200)

  • 主题发起人 主题发起人 hbhxj
  • 开始时间 开始时间
H

hbhxj

Unregistered / Unconfirmed
GUEST, unregistred user!
各位高手,我现在和别人对接的一接口,对方告诉我调用windows中的Msxml2.XMLHTTP调用,但是我怎么调用都提示参数不正确,急。。。procedure TForm1.ButtonClick(Sender: TObject);var url, tempStr, str_result, user, pass: WideString;
responseText: WideString;
xmlHttp: OLEVariant;
xmlDoc: IXMLDOMDocument;
xmlNode: IXMLDOMNode;
i: Integer;begin
user := Trim(Edit2.Text);
pass := Trim(Edit3.Text);
xmlHttp := CreateOleObject('Msxml2.XMLHTTP');
//url := 'http://localhost:8080/cdxtclient/cdxtjumbo?returntype=xml';
url := Trim(Edit1.Text);
xmlHttp.open('post', url, false);
tempStr := '<?xml version=''1.0'' encoding=''utf-8''?>' + '<request>' + '<action_name>authen
ticateAction</action_name>' + '<method_name>authen
ticate</method_name>' + '<list> ' + '<object name=''Users''>' + '<param name=''code''>' + user + '</param>' + '<param name=''password''>' + pass + '</param>' + '</object>' + '</list>' + '</request>';
tempStr := 'abc';
//xmlHttp.setRequestHeader('CONTENT-LENGTH', tempStr.Length);
// xmlHttp.setRequestHeader('CONTENT-TYPE', 'text/xml;
charset=utf-8');
ShowMessage(tempStr);
xmlHttp.send(tempStr);
Memo1.Lines.Add(xmlHttp.responseText);
responseText := xmlHttp.responseText;
if ParseXML(responseText, 'result') <> 'success' then
begin
ShowMessage('登陆失败');
end;

xmlHttp := Unassigned;end;
 
调用哪个参数不正确?其实没有必要用这个吧,在Delphi中直接用Indy是最方便的。
 
Send参数类型错误,需要定义为OleVaraint类型。下面参考例子。procedure TForm1.Button1Click(Sender: TObject);var SendStr, MyHTML: OleVariant;begin
SendStr := 'aa=asa';
MyHTML := CreateOleObject('MSXML2.XMLHTTP');
MyHTML.open('Post', 'http://localhost/index.asp', false);
MyHTML.setRequestHeader('Content-Length', Length(SendStr));
MyHTML.setRequestHeader('CONTENT-TYPE', 'application/x-www-form-urlencoded');
MyHTML.send(SendStr);
ShowMessage(MyHTML.responseText);end;
Dispatch IXMLHTTPRequest;
// IXMLHTTPRequest InterfaceGUID={ED8C108D-4349-11D2-91A4-00C04F7969E8};
function QueryInterface(riid:^GUID;
out ppvObj:^^void);
function AddRef: UI4;
function Release: UI4;
function GetTypeInfoCount(out pctinfo:^UINT);
function GetTypeInfo(itinfo:UINT;
lcid:UI4;
out pptinfo:^^void);
function GetIDsOfNames(riid:^GUID;
rgszNames:^^I1;
cNames:UINT;
lcid:UI4;
out rgdispid:^I4);
function Invoke(dispidMember:I4;
riid:^GUID;
lcid:UI4;
wFlags:UI2;
pdispparams:^DISPPARAMS;
out pvarResult:^variant;
out pexcepinfo:^EXCEPINFO;
out puArgErr:^UINT);
function open(bstrMethod:BSTR;
bstrUrl:BSTR;
[varAsync:variant;
bstrUser:variant;
bstrPassword:variant]);
function setRequestHeader(bstrHeader:BSTR;
bstrValue:BSTR);
function getResponseHeader(bstrHeader:BSTR): BSTR;
function getAllResponseHeaders: BSTR;
function send([varBody:variant]);
function abort;
property-get status: I4;
property-get statusText: BSTR;
property-get responseXML: IDispatch;
property-get responseText: BSTR;
property-get responseBody: variant;
property-get responseStream: variant;
property-get readyState: I4;
property-put onreadystatechange(IDispatch);
 
接受答案了.
 
后退
顶部