当前位置:编程学习 > C#/ASP.NET >>

c#如何调用restful风格的java WebService,急求

项目上需要调用第三方的WS接口,是restful风格的WS
具体如下:
The server inte易做图ce is restful type WS and uses JSONObject format.
address:
http://ncws.bblbs.net/dev/firstupdate
HTTP Method: POST
Requested sample:
param={"imsi":"460023887603775","session":"hwJPCFmgNRtyOED91iTwpteCY"}
Reply sample:
{"firstupdate":"2011-12-01 11:59:06","lat":30.2656,"lon":120.166,"cep":197.337,"imsi":460023887603775,"type":5200}
{"error":"unkonw param"}
c#具体该怎么调用?能给力例子或者网站参考么?非常感谢 WebService C# --------------------编程问答-------------------- 有木有人帮忙~ --------------------编程问答-------------------- 用HttpWebRequest发送请求,如下:
HttpWebRequest request = WebRequest.Create("http://ncws.bblbs.net/dev/firstupdate") as HttpWebRequest;
--------------------编程问答--------------------
引用 2 楼 iamwangshao 的回复:
用HttpWebRequest发送请求,如下:
HttpWebRequest request = WebRequest.Create("http://ncws.bblbs.net/dev/firstupdate") as HttpWebRequest;

很感谢你,不过能具体点么~~ --------------------编程问答--------------------
引用 3 楼 yufenfei2011 的回复:
Quote: 引用 2 楼 iamwangshao 的回复:

用HttpWebRequest发送请求,如下:
HttpWebRequest request = WebRequest.Create("http://ncws.bblbs.net/dev/firstupdate") as HttpWebRequest;

很感谢你,不过能具体点么~~

大致是这样的:
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.KeepAlive = true;
request.AllowAutoRedirect = false;
request.ContentType = "application/x-www-form-urlencoded";
byte[] postdatabtyes = Encoding.UTF8.GetBytes("param={"imsi":"460023887603775","session":"hwJPCFmgNRtyOED91iTwpteCY"}");
request.ContentLength = postdatabtyes.Length;
Stream requeststream = request.GetRequestStream();
requeststream.Write(postdatabtyes, 0, postdatabtyes.Length);
requeststream.Close();
string resp;
try{
   using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
   {
      StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
      resp = sr.ReadToEnd();
    }
   }
补充:.NET技术 ,  C#
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,