0
我正试图加快我本地软件同步的过程。现在我们发送一个我们需要的每条单独记录的GET请求,并且API发回一个包含该记录数据的JSON字符串,然后将其插入到本地数据库中。这一切都有效,但它可能非常缓慢。我试图加快速度,希望能够发送一个JSON为List<Dictionary<string, string>>
的好方法。这将使得我可以在API端一次请求更多的数据,将它添加到列表中,并将其作为JSON传递回本地计算机。通过GET请求发送JSON列表
眼下在本地端我有:
Encoding enc = System.Text.Encoding.GetEncoding(1252);
using (HttpClient client = new HttpClient())
{
string basicAuth = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", usr, pwd)));
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Clear();
client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Basic", basicAuth);
client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
string requested = JsonConvert.SerializeObject(tableList);
HttpResponseMessage response = client.GetAsync(syncUrl + hash + "/" + requested).Result;
if (!response.IsSuccessStatusCode)
{
// get the error
StreamReader errorStream = new StreamReader(response.Content.ReadAsStreamAsync().Result, enc);
throw new Exception(errorStream.ReadToEnd());
}
}
我的控制器调用如下:
[System.Web.Http.AcceptVerbs("GET")]
[Route("getRecords/{hash}/{requested}")]
public HttpResponseMessage getRecords(string hash, string requested)
每当我做这个称呼它给我一个错误,它无法找到URI我甚至没有在我的API上达到我的断点。我如何得到这个工作,或者有更好的方法来完成我正在做的事情?
如果您不发布,您如何期望我们知道您传递的网址是否正确? –