您的位置:程序门 -> .net技术 -> web services



请求post连接 webservice的方法(c#)


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


请求post连接 webservice的方法(c#)
发表于:2007-12-24 10:09:55 楼主
post   /abcd.asmx/getlist   http/1.1
host:   ws.xxxxx.com
content-type:   application/x-www-form-urlencoded
content-length:   length


http/1.1   200   ok
content-type:   text/xml;   charset=utf-8
content-length:   length

<?xml   version="1.0"   encoding="utf-8"?>
<movies   xmlns="http://www.xxxx.com/">
    <schema   xmlns="http://www.w3.org/2001/xmlschema"> schema </schema> xml </movies>
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
请问在c#或asp.net中怎么通过post方式调用
发表于:2007-12-24 13:10:141楼 得分:0
你可以查看测试该服务页面的源代码,它就是用的http   post方式。
<form   id="form1"   method="post"   action="web服务的url地址/操作名">
  <input   id="text1"   type="text"   name="web服务中的方法需要的参数名"   />
  <input   id="submit1"   type="submit"   value="用post方式调用web服务">
</form>

:)新手的回答,不当之处请指出。
发表于:2007-12-24 13:46:172楼 得分:0
<form       id="form1"       method="post"       action="http://ws.xxxxx.com/abcd.asmx/getlist   ">  
    <input       id="text1"       type="text"       name="web服务中的方法需要的参数名"       />  
    <input       id="submit1"       type="submit"       value="用post方式调用web服务">  
</form>  

ls正解。
发表于:2007-12-24 17:18:233楼 得分:0
                                string   posturl   =   "url";             //带上必要的参数          

                                httpwebrequest   request   =   (httpwebrequest)webrequest.create(posturl);

                                request.cookiecontainer   =   cookie;

                                request.method   =   "post";

                                request.contenttype   =   "application/x-www-form-urlencoded";

                                request.allowautoredirect   =   true;

                                string   strxml   = <book> <author> irina </author> <title> piano   fort   a </title> <price> 4.95 </price> </book> ";

                      //           strxml   =   " <?xml   version=\"1.0\"   encoding=\"utf-8\"   ?> "   +   strxml;

                                byte[]   data   =   encoding.utf8.getbytes(strxml);

                                stream   newstream   =   request.getrequeststream();
                   
                                newstream.write(data,   0,   data.length);
                         
                                newstream.close();

                              httpwebresponse   response   =   (httpwebresponse)request.getresponse();
 
                              stream   stream   =   null;

                              stream   =   response.getresponsestream();

                              streamreader   reader   =   new   streamreader(stream,   system.text.encoding.default,   true);

                              string   file   =   reader.readtoend();

                              myreader.discardbuffereddata();

                              myreader.close();

                              stream.close();

                              filestream   s   =   new   filestream("c:/test.txt",   filemode.create);

                              streamwriter   w   =   new   streamwriter(s,   system.text.encoding.default);

                              w.write(file);

                              w.close();




快速检索

最新资讯
热门点击