繁体   English   中英

c# 错误请求 400

[英]c# bad request 400

所以..我正在尝试使用客户端 ID - app-id - app-key 连接到 api

它在 postman 中作为 header 工作,我将其设置为从参数继承身份验证

我将它添加到 header .....

System.Net.WebException: 'The remote server returned an error:     (400) Bad Request.'

how can i use that in mvc c#

给我错误400

====================================
[HttpPost]
public void Drivere(tripelm trips)
{
using (var client = new HttpClient())
{
client.BaseAddress = newUri("https://***********v2/");

client.DefaultRequestHeaders.Authorization
= new AuthenticationHeaderValue("Authorization", "Basic");
client.DefaultRequestHeaders.Add("client-id", "*******DD0");
client.DefaultRequestHeaders.Add("app-id", "*******");
client.DefaultRequestHeaders.Add("app-key","2aa****d4ad");


//HTTP POST
var postTask = client.PostAsJsonAsync<tripelm>("trips", trips);
postTask.Wait();

var result = postTask.Result;
if (result.IsSuccessStatusCode)
{
// return RedirectToAction("Index");
}}

================================

响应是

Result = {StatusCode: 400, ReasonPhrase: '', Version: 1.1, 
Content: System.Net.Http.StreamContent, Headers:
{
Expect-CT: enforce,max-age=30
Strict-Transport-Security: max-age=157680000
X-Content-Type-Options: nosniff
X-Frame-Options

在此处输入图像描述


在此处输入图像描述


[![enter image description here][3]][3]

现在终于可以工作了

client.BaseAddress = new Uri(client.BaseAddress.ToString());
            var postTask = client.PostAsJsonAsync<tripelm>("trips", captainTrip);
var xresult = postTask.Result; 


var result = postTask.Result;
if (xresult.IsSuccessStatusCode)
{
                
string x = "Nice";
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM