C#版本HTTP POST代码

版本:VS2008 命令行项目

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Net;

using System.IO;

using System.Collections.Specialized;





namespace QbjTestCase

{

    class Program

    {

        static void Main(string[] args)

        {

            //定义webClient对象

            WebClient webClient = new WebClient();



            //定义通信地址 和 JSON数据

            const string URL = "http://www.qingbiji.cn/open/convert_json_to_html";

            string jsonString = "[{\"outAcct\":\"无\",\"createTime\":\"2012-08-09 10:47:08.933\",\"transDate\":\"2012-08-09\",\"category\":\"装修设计\",\"transType\":\"支出\",\"inAmount\":0,\"memo\":\"\",\"outAmount\":-25,\"currency\":\"人民币\"},{\"outAcct\":\"无\",\"createTime\":\"2012-08-09 10:47:40.942\",\"transDate\":\"2012-08-09\",\"category\":\"装修设计\",\"transType\":\"支出\",\"inAmount\":0,\"memo\":\"\",\"outAmount\":-35,\"currency\":\"人民币\"},{\"outAcct\":\"无\",\"createTime\":\"2012-08-09 11:15:47.982\",\"transDate\":\"2012-08-09\",\"category\":\"装修设计\",\"transType\":\"支出\",\"inAmount\":0,\"memo\":\"\",\"outAmount\":-36,\"currency\":\"人民币\"},{\"createTime\":\"2012-08-09 11:15:57.903\",\"transDate\":\"2012-08-09\",\"category\":\"装修收入\",\"transType\":\"收入\",\"inAmount\":178,\"memo\":\"\",\"outAmount\":0,\"inAcct\":\"无\",\"currency\":\"人民币\"},{\"outAcct\":\"我的现金\",\"createTime\":\"2012-08-09 11:16:09.292\",\"transDate\":\"2012-08-09\",\"category\":\"\",\"transType\":\"转账\",\"inAmount\":258,\"memo\":\"\",\"outAmount\":-258,\"inAcct\":\"我的活期(卡折)\",\"currency\":\"人民币\"},{\"outAcct\":\"欠中国银行的钱\",\"createTime\":\"2012-08-09 11:16:20.478\",\"transDate\":\"2012-08-09\",\"category\":\"\",\"transType\":\"借入\",\"inAmount\":25478,\"memo\":\"\",\"outAmount\":-25478,\"inAcct\":\"无\",\"currency\":\"人民币\"}]";



            //组装数据

            NameValueCollection postValues = new NameValueCollection(); 

            postValues.Add("json_data", jsonString); 

            postValues.Add("data_name", "装修快帐");

            postValues.Add("client_id", "044083EB67C3DEE783DD802953ED7B3E");



            //向服务器发送POST数据

            byte[] responseArray = webClient.UploadValues(URL, postValues);

            string data = Encoding.ASCII.GetString(responseArray);



            //打印HTTP返回的数据

            Console.WriteLine(data);

        }

    }

}

你可能感兴趣的:(http)