项目上需要调用第三方的WS接口,是restful风格的WS
具体如下:
The server interface 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#具体该怎么调用?能给力例子或者网站参考么?非常感谢WebServiceC#
具体如下:
The server interface 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#具体该怎么调用?能给力例子或者网站参考么?非常感谢WebServiceC#
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();
}
}