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


    }
    };

  • 相关阅读:
    更改eclipse(myeclipse) author的默认名字(注释的作者)
    Myecplise Tomcat 启动很慢
    Java Enum 比较用 == 还是 eques
    Spring JDBC查询返回对象代码跟踪
    Apache启动失败(Windows 无法在本地计算机启动Apache2.2)
    SQLServer2008 统计表占用空间
    SET IDENTITY_INSERT ON/OFF 权限
    字母出现频率
    统计单词数
    查找最大元素
  • 原文地址:https://www.cnblogs.com/luquanmingren/p/3634953.html
Copyright © 2020-2023  润新知