接口问题:postman可以访问对方接口,但是本地代码不行
网页直接访问也可以正常显示,
未找到问题,、、
本以为是
wc.Headers.Add("Accept: application/json");这个限制问题,去掉后发现依然有问题,还是不行。
解决办法,更换代码
原有代码:
WebClient wc = new WebClient(); wc.Encoding = Encoding.UTF8; wc.Headers.Add("Accept: application/json"); wc.Headers.Add("Content-Type: application/json"); result = wc.UploadString(url, "POST", data);
修改为新的方式解决
新代码:
var client = new RestClient(url); client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddParameter("application/json", data, ParameterType.RequestBody); IRestResponse response = client.Execute(request); result = response.Content;