HttpLib - 简化C#调用Web Service的类库

jopen 11年前

HttpLib使得更容易地异步使用C#Web服务的数据。该类库包含了上传文件到服务器,得到网页的方法。
该项目是设计专为调用现有的Web服务。如果你打算写一个新的HTTP客户端/服务器应用程序,我们建议您使用WCF。

支持的方法

  • GET
  • POST
    • Form Encoded
    • Multipart File Upload
    </li>
  • PUT
  • HEAD
  • DELETE
  • </ul>

    从web service获取数据

    Request.get("http://google.com/", (result)=>  {      Console.Write(result);  });

    Post 数据至web service

    Request.post("http://testing.local/post.php", new {name="james",username="Redslide"}, (result)=>  {      Console.Write(result);  });


    Post 数据至web service 并 catch error

    Request.post("http://testing.local/post.php", new { name = "value"}, (result)=>  {      Console.Write(result);  }, (e)=>  {      Console.Write(e.ToString());  });


    上传文件至服务器

    Request.upload("http://testing.local/post.php", new {name = "value"}, new NamedFileStream[] {      new NamedFileStream("file", "photo.jpg", "image/jpeg", @"C:\photo.jpg")  }, (result)=>  {      Console.Write(result);  });

    项目主页:http://www.open-open.com/lib/view/home/1356677790448