1

我正在尝试通过请求将参数发布到返回 JSON 对象的服务。该服务适用于 android 和 iOS。我正试图让它为 wp7 工作。该服务要求内容类型为“应用程序/json”我已粘贴以下设置 http 请求的代码:

            var client = new RestClient(baseurl);
            var request = new RestRequest();
            request.Resource = "login";
            request.Method = Method.POST;
            request.AddHeader("Accept", "application/json");
            request.AddHeader("content-type", "application/json");         
            request.RequestFormat = DataFormat.Json;

            var postData = new Dictionary<string, string>()
            {
                {"key1",value1},
                {"key2",value2}
            };

            request.AddBody(postData); 
            client.ExecuteAsync(request, response =>
            {
                var jsonUser = response.Content;
            });

我从服务器得到的响应错误是内部服务器错误。上面的代码有什么问题吗。我也尝试了 request.AddParameter 方法,但结果相同。代码如下:

            var client = new RestClient(baseurl);
            var request = new RestRequest();
            request.Resource = "login";
            request.Method = Method.POST;
            request.AddHeader("Accept", "application/json");
            request.AddHeader("content-type", "application/json");         
            request.RequestFormat = DataFormat.Json;

            var postData = new Dictionary<string, string>()
            {
                {"key1",value1},
                {"key2",value2}
            };
            var json = JsonConvert.SerializeObject(postData);
            request.AddParameter("application/json", json, ParameterType.RequestBody);
            client.ExecuteAsync(request, response =>
            {
                var jsonUser = response.Content;
            });

在这两种情况下我做错了什么吗?

4

0 回答 0