geeting HTTP Post BAD 请求将 CURL 代码转换为 C# HTTP POST

时间:2021-02-20 17:15:04

标签: c# curl

有人可以帮助需要在 curl 上发布到 url 工作正常但不能通过 C# HTTPPOST ..

这里卷曲代码: curl -H "授权:基本 ZWRpdG9yOnhYTXEgM09QNyB4WjlkIHpET3IgOVNhTiB1S3lx=="-H "描述:{"path":"/shows/sheriffs-el-dorado-county/2020-2021-season"-title""HD SEIN860","date":"2021-02-08","description":"STRIP / HD-SEIN860 / Airdate 02-10-2021"}" -X POST --data-binary @"C:/Users/ sahithi.illindala/Downloads/HD-OZMR13091.pdf"http://ersyndication.wpengine.com/library/wp-json/wp/v2/media

这里是 C# HTTPClient pPOST

使用 (var req = new HttpRequestMessage(new HttpMethod("POST"), "http://ersyndication.wpengine.com/library/wp-json/wp/v2/media"))

        {

            req.Headers.TryAddWithoutValidation("Authorization", "Basic ZWRpdG9yOnhYTXEgM09QNyB4WjlkIHpET3IgOVNhTiB1S3lx==");

            //hc.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("attachment; filename = HD - SEIN860.pdf"));

            req.Headers.TryAddWithoutValidation("Content-Disposition", "attachment; filename=HD-SEIN860.pdf");

            req.Headers.TryAddWithoutValidation("description", "{\"path\":\"/shows/sheriffs-el-dorado-county/2020-2021-season/formats/\",\"title\":\"HD-SEIN860\",\"date\":\"2021-02-08\",\"description\":\"SI1234 / HD-SEIN860 / Airdate 02-10-2021\"}");

            req.Content = new StringContent(File.ReadAllText("path"));

                  req.Content.Headers.ContentType = MediaTypeHeaderValue.Parse("application/x-www-form-urlencoded");

            var response = await httpClient.SendAsync(req).ConfigureAwait(false);


            var JsonResults = await response.Content.ReadAsStringAsync();

0 个答案:

没有答案