首页 新闻 会员 周边 捐助

webclient post数据

0
悬赏园豆:30 [已关闭问题] 关闭于 2011-02-28 11:01

 // 要提交的URL字符串。
            string url = "http://10.249.**.**:8080/geoserver/wfs";

            // 要提交的字符串数据
            string postData = "<wfs:Transaction xmlns:wfs=\"http://www.opengis.net/wfs\" service=\"WFS\" version=\"1.1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd\"> ";
            postData += "<wfs:Insert>";
            postData += "<feature:event xmlns:feature=\"http://www.bjcg.gov.cn/map\">";
            postData += "<feature:the_geom>";
            postData += "<gml:Point xmlns:gml=\"http://www.opengis.net/gml\" srsName=\"EPSG:900913\">";
            postData += "<gml:pos>498790.52946 303557.81882</gml:pos>";
            postData += "</gml:Point>";
            postData += "</feature:the_geom>";
            postData += "<feature:crds>498790.52946,303557.81882</feature:crds>";
            postData += "<feature:bid>110102</feature:bid>";
            postData += "<feature:label>违法小广告</feature:label>";
            postData += "<feature:sourcecode>1</feature:sourcecode>";
            postData += "<feature:zfcode>1101021401000024</feature:zfcode>";
            postData += "<feature:archivetime>2010-12-20 10:47:44.125</feature:archivetime>";
            postData += "<feature:addtime>2010-12-20 10:47:44.125</feature:addtime>";
            postData += "<feature:updatetime>2010-12-20 10:47:44.125</feature:updatetime>";
            postData += "<feature:eventcode>0101</feature:eventcode>";
            postData += "<feature:eventtype>1</feature:eventtype>";
            postData += "</feature:event>";
            postData += "</wfs:Insert>";
            postData += "</wfs:Transaction>";

            //初始化WebClient
            WebClient webClient = new WebClient();
            webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
            //webClient.Headers.Add(

            //将字符串转换成字节数组
            byte[] postBy = Encoding.Default.GetBytes(postData);

            //上传数据,返回页面的字节数组
            //byte[] buff = webclient.DownloadData(url);
            //string cookie = webclient.ResponseHeaders.Get("Set-Cookie");
            byte[] responseData = webClient.UploadData(url, "POST", postBy);

            // 将返回的将字节数组转换成字符串(HTML);
            // ASP.NET 返回的页面一般是Unicode,如果是简体中文应使用
            // Encoding.GetEncoding("GB2312").GetString(responseData)
            string srcString = Encoding.Default.GetString(responseData);

高手们帮忙看下这段代码有什么问题吗,为什么提交到服务器后服务器返回的信息说是没有任何参数传递过去

accpyys的主页 accpyys | 初学一级 | 园豆:134
提问于:2010-12-21 12:12
< >
分享
所有回答(2)
0

very differcult!

jianhua100 | 园豆:200 (初学一级) | 2010-12-22 11:50
0

在 webClient.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
下面加上:

webClient.Headers.Add("ContentLength", postBy.Length.ToString());

就可以了

ilovemeyou2000 | 园豆:187 (初学一级) | 2011-10-21 03:05
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册