Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/313.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# HttpClient Post请求未在C中发送Post参数#_C#_.net_Winforms_Api_Httpclient - Fatal编程技术网

C# HttpClient Post请求未在C中发送Post参数#

C# HttpClient Post请求未在C中发送Post参数#,c#,.net,winforms,api,httpclient,C#,.net,Winforms,Api,Httpclient,我正在控制台应用程序中发送post请求,但它似乎无法发送post参数。 这是我的密码 { string pass_url = "https://staging.fooddesk.be/api/v1/add_new_partner_pws"; string postString = "[{\n\"product_name\": \"kip absrert\",\n\"producer_name\&quo

我正在控制台应用程序中发送post请求,但它似乎无法发送post参数。 这是我的密码

{
    string pass_url = "https://staging.fooddesk.be/api/v1/add_new_partner_pws";
    string postString = "[{\n\"product_name\": \"kip absrert\",\n\"producer_name\": \"Imperial Meat Products\",\n\"producer_art_num\": \"123\",\n\"supplier_name\": \"Vagro\",\n\"supplier_art_num\": \"12345\",\n\"ean_code\": \"5411153011327\",\n\"partner_art_nbr\": \"12345\"\n}]\"";
    var multipartContent = new MultipartFormDataContent();
    multipartContent.Add(new StringContent("pws_data" ) , postString) ;
    Uri requestUri = new Uri(pass_url);
    using (var objClint = new System.Net.Http.HttpClient())
    {
        objClint.DefaultRequestHeaders.Add("X-API-KEY", "ABCD");
        objClint.DefaultRequestHeaders.Add("X-COMP-KEY", "XYZ");
        System.Net.Http.HttpResponseMessage response = objClint.PostAsync(requestUri, multipartContent).Result;
        Console.WriteLine(response);
        if (response.IsSuccessStatusCode)
        {
            string json = response.Content.ReadAsStringAsync().Result;
            Console.WriteLine(json);
        }
    }
}
我在第四行遇到一个例外。 请让我知道如何在http客户端post请求中发送post数据。
提前谢谢。

我相信你在第4行中混淆了你的论点

查看使用情况

试一试

此外,post字符串在后面有一个额外的引号]。移除这些应该会有所帮助

[{ “产品名称”:“kip absrert”, “生产商名称”:“帝国肉制品”, “制作人艺术数量”:“123”, “供应商名称”:“Vagro”, “供应商编号”:“12345”, “ean_代码”:“5411153011327”, “合伙人艺术编号”:“12345”
}]“

您好,谢谢,我更新了那一行,例外情况消失了。但是api的另一面仍然没有得到发布的参数。有什么线索吗?我收到403禁止回复。可能API键或COMP键不正确。我现在收到400个错误的请求响应。我会用你的API密钥和Comp密钥删除上面的评论。是的,它返回400,因为pws\U数据对另一方不可用。字符串postString=“[{\n\“产品名称”:“kip absrert\”,\n\“生产商名称”:“帝国肉类产品”,\n\“生产商艺术数量”:“123\,\n\“供应商名称”:“Vagro\,\n\“供应商艺术数量”:“12345\,\n\”ean\U代码\“:\“5411153011327\”,\n \“合作伙伴\u艺术\u nbr\”:“12345\”\n}]\”;最后,在“]”字符后,删除\“。这是在请求中添加了一个额外的双引号。当你收到“异常”时,发布准确的消息非常有用-通常包含有用的信息。。。一如既往:
multipartContent.Add(new StringContent(postString) , "pws_data") ;