接口問題: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;