Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Rest 带有正文和压缩数据的POST请求_Rest_File_Upload - Fatal编程技术网

Rest 带有正文和压缩数据的POST请求

Rest 带有正文和压缩数据的POST请求,rest,file,upload,Rest,File,Upload,我想在POST请求中发送一个zip(.txt)文件以及请求中的一些JSON参数。 post请求的示例请求和标题应该是什么。 在POST URL中添加varibales是正确的方法吗? 例如:POST Example.com/v1/name/{name}/Phone/{Phone}/date/{date}/upload [test.txt] 请建议。您应该将文件转换为字节数组,并将其作为请求正文参数添加到请求中。使用.NET的RestSharp,以下是我如何将文件添加到请求中的: RestRequ

我想在POST请求中发送一个zip(.txt)文件以及请求中的一些JSON参数。 post请求的示例请求和标题应该是什么。 在POST URL中添加varibales是正确的方法吗? 例如:POST Example.com/v1/name/{name}/Phone/{Phone}/date/{date}/upload

[test.txt]


请建议。

您应该将文件转换为
字节
数组,并将其作为请求正文参数添加到请求中。使用.NET的
RestSharp
,以下是我如何将文件添加到请求中的:

RestRequest request = new RestRequest("api/someEndpoint", Method.POST);
request.AddHeader("Content-Type", "text/plain"); // optional: depends on API
request.AddHeader("File-Name", fileName); // optional: depends on API

// add the file here. you need to provide the absolute path to it
request.AddParameter("text/plain", File.ReadAllBytes(absolutePathToYourFile), ParameterType.RequestBody);

注意:根据您关于使用
.txt
文件的评论,我使用了
内容类型:text/plain
。但是,如果您的文件扩展名是
.zip
,则需要使用
应用程序/zip
作为
内容类型
参数。

您应该将文件转换为
字节
数组,并将其作为请求正文参数添加到请求中。使用.NET的
RestSharp
,以下是我如何将文件添加到请求中的:

RestRequest request = new RestRequest("api/someEndpoint", Method.POST);
request.AddHeader("Content-Type", "text/plain"); // optional: depends on API
request.AddHeader("File-Name", fileName); // optional: depends on API

// add the file here. you need to provide the absolute path to it
request.AddParameter("text/plain", File.ReadAllBytes(absolutePathToYourFile), ParameterType.RequestBody);
注意:根据您关于使用
.txt
文件的评论,我使用了
内容类型:text/plain
。但是,如果您的文件扩展名是
.zip
,则需要使用
应用程序/zip
作为
内容类型
参数