zoukankan      html  css  js  c++  java
  • wp8 入门到精通 WebClient Post

    WebClient wc = new WebClient();

    var URI = new Uri("http://your_uri_goes_here");

    //If any encoding is needed.

    wc.Headers["Content-Type"] = "application/x-www-form-urlencoded";

    //Or any other encoding type.

    //If any key needed

    wc.Headers["KEY"] = "Your_Key_Goes_Here";

    wc.UploadStringCompleted += new UploadStringCompletedEventHandler(wc_UploadStringCompleted);

    wc.UploadStringAsync(URI, "POST", "Data_To_Be_sent");

    void wc_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {

    try
    {
    MessageBox.Show(e.Result);
    //e.result fetches you the response against your POST request.

    }

    catch (Exception exc)
    {
    MessageBox.Show(exc.ToString());
    }

    }

    ===================================================

    using Newtonsoft.Json.Linq;
    using Newtonsoft.Json;

     JObject ubody = new JObject();

    ubody.Add(new JProperty("cmd", "user"));
    JObject uData = new JObject();
    uData.Add(new JProperty("name", ""));
    uData.Add(new JProperty("sex", ""));
    uData.Add(new JProperty("age", ""));
    ubody.Add(new JProperty("data", uData));

    string Content = JsonConvert.SerializeObject(ubody);

    Uri address = new Uri("http://api.api.cn/");
    WebClient webClient = new WebClient();
    webClient.UploadStringAsync(address, "POST", Content);
    webClient.Encoding = System.Text.Encoding.UTF8;
    webClient.Headers[HttpRequestHeader.Accept] = "*/*";
    webClient.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
    webClient.Headers[HttpRequestHeader.UserAgent] = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1)";
    webClient.UploadStringCompleted += (s1, e1) =>
    {
    try
    {
    ShellToast toast = new ShellToast();
    toast.Title = "Background Agent Sample";
    toast.Content = e1.Result;
    toast.Show();

    }
    catch (Exception ex)
    {


    }
    };

  • 相关阅读:
    sql 日期格式化 比较全面
    SQL Server 2005 中的树形数据处理示例1
    Web网站的性能测试工具
    js实现时分秒
    sql查询远程数据库的表的数据并填充到本地数据库的表
    Windows 2003操作系统十四招加速大法
    window2003 server的一些优化设置_windows 2003
    解决html向aspx页面传值汉字乱码问题
    js快捷键大全 http://www.zhangxinxu.com/wordpress/?p=1667
    iis 重启命令
  • 原文地址:https://www.cnblogs.com/luquanmingren/p/3634953.html
Copyright © 2011-2022 走看看