客户端delphi使用XML与中间层C#.net通信的例子,客户端用idhttp的post发送请求.doc_第1页
客户端delphi使用XML与中间层C#.net通信的例子,客户端用idhttp的post发送请求.doc_第2页
客户端delphi使用XML与中间层C#.net通信的例子,客户端用idhttp的post发送请求.doc_第3页
客户端delphi使用XML与中间层C#.net通信的例子,客户端用idhttp的post发送请求.doc_第4页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

客户端delphi使用XML与中间层C#.net通信的例子,客户端用idhttp的post发送请求1. 客户端代码:1. unitUnit1;2.3. interface4.5. uses6. Windows,Messages,SysUtils,Variants,Classes,Graphics,Controls,Forms,7. Dialogs,IdBaseComponent,IdComponent,IdTCPConnection,IdTCPClient,8. IdHTTP,StdCtrls;9.10. type11. TForm1=class(TForm)12. IdHTTP1:TIdHTTP;13. Button1:TButton;14. Button2:TButton;15. Memo1:TMemo;16. procedureButton2Click(Sender:TObject);17. private18. Privatedeclarations19. public20. Publicdeclarations21. end;22.23. var24. Form1:TForm1;25.26. implementation27.28. $R*.dfm29.30. procedureTForm1.Button2Click(Sender:TObject);31. var32. respsm:TStringStream;33. AList:TStrings;34. uri:string;35. begin36. uri:=http:/localhost:4983/WebSite3/Default.aspx;/这个地址换成自己的响应地址37. AList:=TStringList.Create;38. 中文乱码问题解决方法:发送过去之前先转码UTF8Encode,接收的时候再解码UTF8Decode39. AList.Add(UTF8Encode(Memo1.Text);40.41. respsm:=TStringStream.Create();42. /IdHTTP1.Get(http:/localhost:4983/WebSite3/Default.aspx?id=3,sm);43. IdHTTP1.Request.ContentType:=application/x-www-form-urlencoded;44. try45. IdHTTP1.Post(uri,AList,respsm);46. finally47. ShowMessage(UTF8Decode(respsm.DataString);/respsm.DataString为中间层返回的数据48. end;49.50. respsm.Free;51. AList.Free;52.53. end;54.55. end.客户端memo1.Text的内容为(在设计界面直接编辑memo1.lines,输入以下内容):1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 中间层代码:(Default.aspx.cs)1. usingSystem;2. usingSystem.Data;3. usingSystem.Configuration;4. usingSystem.Web;5. usingSystem.Web.Security;6. usingSystem.Web.UI;7. usingSystem.Web.UI.WebControls;8. usingSystem.Web.UI.WebControls.WebParts;9. usingSystem.Web.UI.HtmlControls;10. /添加以下命名空间11. usingSystem.Xml;12. usingSystem.Data.Sql;13. usingSystem.Data.SqlClient;14. usingSystem.IO;15. usingSystem.Text;16.17. publicpartialclass_Default:System.Web.UI.Page18. 19. protectedvoidPage_Load(objectsender,EventArgse)20. 21.22. Streamsm=Request.InputStream;23. sm.Position=0;24. bytebuff=newbytesm.Length;25. /charbuff=newcharsm.Length;26. intlen=(int)sm.Length;27. sm.Read(buff,0,len);28. /StreamReadersr=newStreamReader(sm);29. /sr.Read(buff,0,len);30. stringstr=Encoding.UTF8.GetString(buff);31.32. str=Server.UrlDecode(str);33.34. stringID=null;35. stringAttrList=newstring2;36.37. XmlDocumentdom=newXmlDocument();38. dom.LoadXml(str);39. XmlNodeListxnl=dom.GetElementsByTagName(client);40. if(xnl0.Attributes0.Value.ToString().StartsWith(RoleInfo_)41. 42. if(xnl0.Attributes0.Value.ToString().EndsWith(New)43. 44. for(inti=0;iAttrList.Length;i+)45. 46. AttrListi=xnl0.ChildNodes0.Attributesi+1.Value;47. 48. SqlConnectionconn=newSqlConnection(server=.;database=test;uid=xj;pwd=123456);49. conn.Open();50. SqlCommandcomm=newSqlCommand();51. comm.Connection=conn;52. comm.CommandText=insertintoRoleInfo(Name)values(Name);selectidentityasid;53. comm.Prepare();54. 55. comm.Parameters.Add(Name,SqlDbType.VarChar,50);56. comm.Parameters0.Direction=ParameterDirection.Input;57. comm.Parameters0.Value=AttrList1;58. /取刚插入数据库的记录的ID59. DataSetds=newDataSet();60. SqlDataAdaptersda=newSqlDataAdapter(comm);61. sda.Fill(ds);62.63. comm.Dispose();64. conn.Close();65. conn.Dispose();66.67. ID=ds.Tables0.Rows00.ToString();68. /插入成功将ID返回给客户端69. Response.Clear();70. Response.ContentType=text/xml;71. Response.Write();72. Response.Write()

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论