如何在 Visual Studio 调试中查看发送到服务的请求数据?
How to see request data being sent to service in Visual Studio Debug?
如何查看 Visual Studio 中请求中实际发送的 json 数据以验证其格式正确并在数据出现问题时进行故障排除?
我有一个带有示例代码的 StockItem class:
public class StockItem
{
私有字符串 _recID;
[JsonProperty("recid")]
public string RecID
{
get { return _recID; }
set { _recID = value; }
}
)
这应该将传递给 Web 服务的列的名称设置为与其列匹配的名称。
public static async Task ProcessItemsAsync(object content, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.BaseAddress = new Uri(BaseURL);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "tokencode");
using (var request = new HttpRequestMessage(HttpMethod.Post, itemUrl))
{
var json = JsonConvert.SerializeObject(content);
using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
request.Content = stringContent;
using (var response = await client
.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
.ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
}
}
}
}
}
我在 Visual Studio 中查看 Locals 或 Autos...我可以在内容 [0] 中看到我的 StockItem 对象。但不在 request.Content 中。
响应的原因是错误的请求。我该如何解决这个问题?
RequestMessage 是 "Bad Request"。对不起...我对此感到非常沮丧。
您可以轻松地看到使用 Fiddler 发送的请求。据我所知,您在 Visual Studio.
中看不到它
如何查看 Visual Studio 中请求中实际发送的 json 数据以验证其格式正确并在数据出现问题时进行故障排除?
我有一个带有示例代码的 StockItem class: public class StockItem { 私有字符串 _recID;
[JsonProperty("recid")]
public string RecID
{
get { return _recID; }
set { _recID = value; }
}
)
这应该将传递给 Web 服务的列的名称设置为与其列匹配的名称。
public static async Task ProcessItemsAsync(object content, CancellationToken cancellationToken)
{
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Accept.Clear();
client.BaseAddress = new Uri(BaseURL);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", "tokencode");
using (var request = new HttpRequestMessage(HttpMethod.Post, itemUrl))
{
var json = JsonConvert.SerializeObject(content);
using (var stringContent = new StringContent(json, Encoding.UTF8, "application/json"))
{
request.Content = stringContent;
using (var response = await client
.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken)
.ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
}
}
}
}
}
我在 Visual Studio 中查看 Locals 或 Autos...我可以在内容 [0] 中看到我的 StockItem 对象。但不在 request.Content 中。
响应的原因是错误的请求。我该如何解决这个问题?
RequestMessage 是 "Bad Request"。对不起...我对此感到非常沮丧。
您可以轻松地看到使用 Fiddler 发送的请求。据我所知,您在 Visual Studio.
中看不到它