答案 0 :(得分:0)
像这样:
public static string getResponseFromwebService(string serviceUrl)
{
var baseurl = "http://localhost:1936/";
var auth= "123456";
var apid = "1";
var requestUrl = baseurl + serviceUrl;
WebRequest request = WebRequest.Create(requestUrl);
request.Headers.Add("Authorisation", auth);
request.Headers.Add("appId", apid);
WebResponse response = request.GetResponse();
Stream dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
reader.Close();
response.Close();
return responseFromServer;
}
您希望将变量保留在某些配置中,并且可能将响应序列化为各种对象。