C#版本HTTP POST代碼

來源:互聯網
上載者:User

版本: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);        }    }}
相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.