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)
    {


    }
    };

  • 相关阅读:
    lombok的介绍及使用
    java后端导入excel将数据写入数据库
    java后端导出excel表格
    eclipse maven打war包
    java后端树形菜单使用递归方法
    mybatis一对多查询
    @transactional作用和事务
    zookeeper安装
    Solr单机版安装
    jstat 简介(2)
  • 原文地址:https://www.cnblogs.com/androllen/p/3634953.html
Copyright © 2011-2022 走看看