带有C#参数的Web服务请求

时间:2016-10-27 14:19:11

标签: c# rest parameter-passing httpwebresponse .net-4.5.2

我有网络休息服务,它接受一个学生ID参数并带回学生记录。我很难将参数传递给服务而且它没有发生

string StudentByPeopleCodeServiceURL = https://agentwebservices.ac.uk/Rest/Modules/15427/Screens/U_LookUps/Data/StudentByCode
我需要传递的

参数是

{PeopeCode}= 307242

和代码是

HttpWebRequest _Request = (System.Net.HttpWebRequest)WebRequest.Create(string.Format(StudentByPeopleCodeServiceURL));

   try
       {
         _Request.Method = "GET";

         _Request.ContentType = "text/xml";

         _Request.Accept = "text/xml";

         _Request.UserAgent = "Mozilla/4.0+(compatible;+MSIE+5.01;+Windows+NT+5.0";

   _Request.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-us");

   _Request.Headers.Add(HttpRequestHeader.Authorization, token.EBS_Token);

 HttpWebResponse _Response = _Request.GetResponse() as HttpWebResponse;


   _WebServiceStatus.ResponseStatusCode = _Response.StatusCode;
   _WebServiceStatus.ResponseContentLength = _Response.ContentLength;
   _WebServiceStatus.ResponseContentType = _Response.ContentType;

    //rest of code

我试过在url中传递参数吗?PeopeCode = 307242但是它无效。 Rest API是外部的,我无法控制它

非常感谢提前

1 个答案:

答案 0 :(得分:0)

如果这是一个休息网络服务,请尝试添加参数" {PeopeCode} = 307242"如下例所示:

https://agentwebservices.ac.uk/Rest/Modules/15427/Screens/U_LookUps/Data/StudentByCode/307242

通常,查询字符串与搜索方案有关:REST API DESIGN - Getting a resource through REST with different parameters but same url pattern