如何使用原始字符串作为参数进行GET请求

时间:2015-10-27 11:18:36

标签: c# json get servicestack

我有下一个API网址,可以在网站http://api.dev.socialtord.com/api/Friend/GetFriends上获取用户的朋友。根据文件 http://api.dev.socialtord.com/Help/Api/GET-api-Friend-GetFriends它需要原始的json字符串,用户ID为param。我尝试获得正确答案的所有尝试都失败了。

服务:

public class FriendsService
{
    readonly string _apiUrl = "http://api.dev.socialtord.com/api";

    public JsonServiceClient CallClient()
    {
        // wire up call
        var client = new JsonServiceClient(_apiUrl);
        return client;
    } 

    public List<FriendListModel> GetFriends(long userId)
    {
        try
        {
            var client = CallClient();
            var response = client.Get<GetFriendsResponse>(new GetFriends() { UserId = userId} );
            if (response.ErrorMessage == null)
                return response.Result;
            else
                return null;
        }
        catch (Exception e)
        {
            System.Diagnostics.Debug.WriteLine("[GetFriends Excetion] " + e.Message);
        }
        return null;
    }
}

请求:

[Route("/Friend/GetFriends", "GET")]
public class GetFriends : IReturn<GetFriendsResponse>, IReturnVoid
{
    public long UserId { get; set; }
}

响应:

public class GetFriendsResponse
{
    public List<FriendListModel> Result { get; set; }
    public ResponseStatus ResponseStatus { get; set; }
    public string ErrorMessage { get; set; }
    public int ErrorCode { get; set; } 
} 

型号:

[ImplementPropertyChanged]
public class FriendListModel
{
    public long UserId { get; set; }
    public string PlayerHandle { get; set; }
    public string Gender { get; set; }
    public string Picture { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public long RelatedUserId { get; set; }
    public string UserName { get; set; }
    public string FacebookId { get; set; }
    public long UserRelationshipId { get; set; }
    public DateTime? DateCreated { get; set; }
    public DateTime? DOB { get; set; }
} 

0 个答案:

没有答案