C# 发送参数&;请求正文中带有原始请求头C的文件#
我正在尝试发送请求正文中的参数和文件,原始请求标题为C#Console/Asp.Net(Web表单)Web应用程序。 我看了很多例子,但没有找到合适的解决方案 我已经尝试了下面的代码,几乎可以正常工作了。唯一的问题是无法获得任何解决方案来发送请求正文中的文件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
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吗?你知道这件事吗?