我试图在外部服务上发出一个json请求,如下所示:
GET请求:
https://remotehost/path/mycount?foo=C&bar=21
回应:
{"count":1000}
为此我使用ServiceStack JsonServiceClient,我喜欢它,因为你可以传递一个对象作为参数。这使它易于使用/阅读。
这是我的代码:
var client = new JsonServiceClient(classifiedSearchBaseURL);
var response = client.Get<CountResponse>(
new MyRequest
{
foo = "C",
bar = 21
});
class MyRequest
{
public string foo { get; set; }
public int bar { get; set; }
}
class CountResponse
{
public string count;
}
但是在调试时,而不是将此http请求发送到服务器
GET /path/mycount?foo=C&bar=21
我得到了这个
GET /path/json/reply/MyRequest?foo=C&bar=21
你们中的任何一个人都有想法吗?
谢谢你的帮助!
答案是我应该将Route属性用于Request对象
以下是修改后的代码
[ServiceStack.Route("/mycount")]
class MyRequest
{
public string foo { get; set; }
public int bar { get; set; }
}