【发布时间】:2019-11-12 05:15:55
【问题描述】:
我正在尝试将订单发布到 PayU 支付网关,使用像 post man 这样的 Rest Client 工具,我也遇到了同样的问题。
我正在尝试使用C#发布,订单创建成功但响应不符合预期,应该是一个json对象,包含插入的订单id和重定向url,但当前是html响应!
我使用 restsharp 库的 C# 代码:
public IRestResponse<CreateOrderResponseDTO> CreateOrder(CreateOrderDTO orderToCreate)
{
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
var actionUrl = "/api/v2_1/orders/";
var client = new RestClient(_baseUrl);
var request = new RestRequest(actionUrl, Method.POST)
{
RequestFormat = DataFormat.Json
};
request.AddJsonBody(orderToCreate);
request.AddHeader("authorization", $"Bearer {_accessToken}");
request.AddHeader("Content-Type", "application/json");
var response = client.Execute<CreateOrderResponseDTO>(request);
if (response.StatusCode == HttpStatusCode.OK)
{
return response;
}
throw new Exception("order not inserted check the data.");
}
我使用内置 WebRequest 的 C# 代码也返回相同的 html:
public string Test(string url, CreateOrderDTO order)
{
var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
httpWebRequest.ContentType = "application/json";
httpWebRequest.Accept = "application/json";
httpWebRequest.Method = "POST";
httpWebRequest.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + _accessToken);
using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
{
streamWriter.Write(new JavaScriptSerializer().Serialize(order));
}
var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
return result;
}
}
谁能告诉我在这里错过了什么?
【问题讨论】:
-
什么是 HTML?是错误页面吗?
-
@Amy 您好,该html包含一个巨大的svg文件,您可以找到html文件供您参考drive.google.com/…