BOX REST API中忽略搜索查询参数

时间:2015-04-23 09:19:48

标签: box-api

我正在尝试使用VS2013中的restsharp调用方法搜索。 Box忽略subquery字符串。我查阅过文档,然后用“PostMan”测试了调用,效果很好。

        string query = "asterisk";
        string subquery = "file_extensions=docx";

        var client = new RestClient(BASE_URL);
        client.Authenticator = new OAuth2AuthorizationRequestHeaderAuthenticator(DEV_ACCESS_TOKEN, "Bearer");

        var request = new RestRequest(Method.GET);
        request.Resource = "search?query={query}&{subquery}";
        request.AddParameter("query", query, ParameterType.UrlSegment);
        request.AddParameter("subquery", subquery, ParameterType.UrlSegment);

        request.RequestFormat = DataFormat.Json;            

        var response = client.Execute(request);
        var content = response.Content;

此致

1 个答案:

答案 0 :(得分:1)

问题是您要将整个file_extensions=docx字符串添加为网址参数。 RestSharp是对=进行URL编码,而Box则忽略了格式错误的字符串。

GET /2.0/search?query=asterisk&file_extensions%3Ddocx

以下更改将产生正确的结果:

string subquery = "docx";
request.Resource = "search?query={query}&file_extensions={subquery}";
request.AddParameter("subquery", subquery, ParameterType.UrlSegment);

GET /2.0/search?query=asterisk&file_extensions=docx