use msxml
Delphi 6 里idhttp貌似没有Header里的一些东西的处理方法。也是摸索了很久,记录一下。
function HttpRequest(http: TIdHttp; strUrl: string; inStr: string; var outStr, Errmsg: string): boolean; var HttpReq:IXMLHttpRequest; begin Result := false; try HttpReq := CoXMLHTTPRequest.Create; HttpReq.open('Post', strUrl, False, EmptyParam, EmptyParam); HttpReq.setRequestHeader('Accept', 'application/json; charset=utf-8'); HttpReq.setRequestHeader('Authorization','26CEECF313091306'); HttpReq.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); HttpReq.send((inStr)); outStr := (HttpReq.responseText); result := true; except on E: Exception do begin Errmsg := '接口调用错误:'+ #13#10 + E.Message; WriteLog(Errmsg); end; end; { with http do begin lstParam := TStringlist.Create; lstStream := TStringStream.Create(''); try try lstParam.Add(UTF8Encode(inStr)); Post(strUrl, lstParam, lstStream); outStr := Utf8Decode(lstStream.DataString); Result := True; except on E: Exception do begin Errmsg := '接口调用错误:'+ #13#10 + E.Message; WriteLog(Errmsg); end; end; finally lstParam.Free; lstStream.Free; end; end; } end;