Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/264.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# 发送参数&;请求正文中带有原始请求头C的文件#_C#_Post_Webclient_Dotnet Httpclient_Request Headers - Fatal编程技术网

C# 发送参数&;请求正文中带有原始请求头C的文件#

C# 发送参数&;请求正文中带有原始请求头C的文件#,c#,post,webclient,dotnet-httpclient,request-headers,C#,Post,Webclient,Dotnet Httpclient,Request Headers,我正在尝试发送请求正文中的参数和文件,原始请求标题为C#Console/Asp.Net(Web表单)Web应用程序。 我看了很多例子,但没有找到合适的解决方案 我已经尝试了下面的代码,几乎可以正常工作了。唯一的问题是无法获得任何解决方案来发送请求正文中的文件 public class requestObj { public string langType { get; set; } } protected void CreateUser

我正在尝试发送请求正文中的参数和文件,原始请求标题为C#Console/Asp.Net(Web表单)Web应用程序。 我看了很多例子,但没有找到合适的解决方案

我已经尝试了下面的代码,几乎可以正常工作了。唯一的问题是无法获得任何解决方案来发送请求正文中的文件

 public class requestObj
        {
            public string langType { get; set; }
        }

protected void CreateUser_Click(object sender, EventArgs e)
        {
            try
            {           
                var requestObj = new requestObj
                {
                    langType = "aaa"
                };

                var client = new RestSharp.RestClient(url);
                client.Timeout = -1;
                var request = new RestSharp.RestRequest(RestSharp.Method.POST);
                request.AddHeader("Origin", "http://localhost:8080");
                request.AddJsonBody(requestObj);
                var response = client.Execute(request);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

谢谢,

我通过以下方式使它工作

string url = requestUrl;
string filePath = @"F:\text.txt";


 var client = new RestSharp.RestClient(url);
                    client.Timeout = -1;
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("Origin", "http://localhost:2020");
                    request.AddParameter("parameter", "parameterValue");
                    request.AddFile("file", filePath, "text/plain"); //file parameter.
                    IRestResponse response = client.Execute(request);
                    Console.WriteLine(response.Content);

我通过以下方式使其工作

string url = requestUrl;
string filePath = @"F:\text.txt";


 var client = new RestSharp.RestClient(url);
                    client.Timeout = -1;
                    var request = new RestRequest(Method.POST);
                    request.AddHeader("Origin", "http://localhost:2020");
                    request.AddParameter("parameter", "parameterValue");
                    request.AddFile("file", filePath, "text/plain"); //file parameter.
                    IRestResponse response = client.Execute(request);
                    Console.WriteLine(response.Content);

检查此项谢谢您的回复。。。我会查的,一定查这个。。但是我们可以使用WebClient吗?你对此有什么想法吗?看看这个谢谢你的回复。。。我会查的,一定查这个。。但是我们可以使用WebClient吗?你知道这件事吗?